Windows Path finding not working

L

Loxias

Guest
Hello GMC,

I am having some issues with my AI. When my player moves he creates a trail of slime behind him, but the AI gets "stuck" in it, and refuse to move unless the player has roughly the same X or Y axis. Here is the code:
Code:
grid = mp_grid_create(0,0,room_width/16,room_height/16,16,16);
grid = mp_grid_create(0,0,room_width/16,room_height/16,16,16);
path = path_add();
mp_grid_add_instances(path,objWall,true);
mp_grid_path(grid,path,x,y,objPlayer.x,objPlayer.y,true);
path_start(path,0.8,"",true);
It is also worth mentioning that the AI will try to pathfind around the slime, and only enter if the player matches its own X or Y position.

Thanks in advance,
Loxias
 

NightFrost

Member
Is all of that in step event? If the walls are static, there's no need to create the mp grid and add wall instance locations but once on room start. You don't even need to recreate the path every step, since position changes step-to-step are likely minimal. Possibly recalculate only after enemy has moved into next grid cell the path takes it? Also, remember to destroy the path when enemy dies or room changes.

Having said that, the mp path doesn't appear to interact with player slime trail, so the problem would be elsewhere in the code. Possibly in the "pathfind around the slime" code you mention.
 
L

Loxias

Guest
Is all of that in step event? If the walls are static, there's no need to create the mp grid and add wall instance locations but once on room start. You don't even need to recreate the path every step, since position changes step-to-step are likely minimal. Possibly recalculate only after enemy has moved into next grid cell the path takes it? Also, remember to destroy the path when enemy dies or room changes.

Having said that, the mp path doesn't appear to interact with player slime trail, so the problem would be elsewhere in the code. Possibly in the "pathfind around the slime" code you mention.
So basically I should move the mp_grid_create to a Controller create event and give it to the AI from there. Also, as I am making a top down shooter with 8 directional movement, I am a bit confused as to why the AI does not need to recalculate its way to the player. Do you mean that I should put a timer on the AI, and have it recalculate the path only when the timer is done? I have never worked with AI before, so if you could explain it I would appreciate it a lot.(got this code from a tutorial)

Also, sorry if I made myself unclear, but there is no code for the AI to avoid the slime, it just seems to treat it as a wall(even though it shouldn't). I have no clue as to what makes it behave this way.
Edit: and yes everything is in the step event.

Edit 2: The AI only walks up and to the left. Don't know why, I am even more confused at this point... o-o''
 
Last edited by a moderator:

NightFrost

Member
Yeah, I'm saying put either a timer on the enemy, and refresh the path only when certain limit has been reached. Positional changes between individual game steps are small so they don't warrant the recalculation of the path, but only when sufficient time has been covered. If the enemy's intent is to close into melee range, you may want to shorten this counter at close distances so the enemy may better react to sudden player actions.

If your slime object is treated as wall, make sure it is not accidentally being added to the grid elsewhere. Or it may have been set as child of the wall object and gets treated as wall piece. You can debug your motion plan grid with mp_grid_draw which will show you what portions of the grid map the system is treating as inaccessible, put it into a draw event.
 
Top