Dr_Nomz
Member
I have a good path finding AI that allows an NPC to move pretty well:
But sometimes when turning corners it just kinda goes through the wall a little bit, even though it's supposed to hug the wall, or at the very least not be inside of it.
Any way I can fix this?
EDIT: I also have a walking code for the player that might help
Now I don't want to change the NPC code drastically since it works fine, but any chance I can use the same concept here to keep it from sticking into walls?
The code I'm talking about is the part where the while loop keeps the player from being inside of a wall, because if he gets stuck in one for some weird reason, moving just 1 pixel shoots them out on the correct side of the wall.
EDIT2: Actually tested the while loop, can make the NPC shoot out the wrong direction and teleport. <_< Other solutions, or just accept the fact that it partially moves inside of walls?
ALSO could this cause a memory leak the way it's written? See, it calls code from a control object at the start of the game:
I heard from the tutorial I pulled this from that it could cause that, so I altered slightly to hopefully prevent that. If I got it wrong it would be really good to know.
Code:
///STEP
if !place_meeting(x,y,obj_Character){
move_speed=5
mp_grid_path(global.grid,global.path,x,y,obj_Character.x,obj_Character.y,true)
path_start(global.path,move_speed,"",true);
if (distance_to_object(obj_Character) > 2000){
status = npc_state.npc_normal;
}
}
Any way I can fix this?
EDIT: I also have a walking code for the player that might help
Code:
var i=run_speed; while !place_free(x,y-i) i--; y-=i;
var i=run_speed; while !place_free(x,y+i) i--; y+=i;
var i=run_speed; while !place_free(x-i,y) i--; x-=i;
var i=run_speed; while !place_free(x+i,y) i--; x+=i;
The code I'm talking about is the part where the while loop keeps the player from being inside of a wall, because if he gets stuck in one for some weird reason, moving just 1 pixel shoots them out on the correct side of the wall.
EDIT2: Actually tested the while loop, can make the NPC shoot out the wrong direction and teleport. <_< Other solutions, or just accept the fact that it partially moves inside of walls?
ALSO could this cause a memory leak the way it's written? See, it calls code from a control object at the start of the game:
Code:
///CREATE
global.grid = mp_grid_create(0,0,room_width/50,room_height/50,50,50);
global.path = path_add();
mp_grid_add_instances(global.path,obj_Wall,1)
Last edited: