• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Path Finding Issue - Path ends whenever player collides with the instance added

M

mzn528

Guest
Hello All, I am back again with a question regarding AI and path finding.

I am currently using mp_grid as a way for enemy to do path finding, how I set this up is:

Code:
Create Event:
ai_grid = mp_grid_create(0,0,room_width/32,room_height/32,32,32);
ai_path = path_add();
mp_grid_add_instances(ai_grid,obj_bound,true);

Step Event:
if(mp_grid_path(ai_grid,ai_path,x,y,player_x,player_y,false))
{//if the path is available then start the path
path_start(ai_path,moveSpeed,path_action_stop,false)
}
else
{//else stop, end path and switch state
speed = 0;
path_end();
state_switch(st_active);
}
Now the issue with this is, the enemy is able to find me alright but as soon as I collide with obj_bound (the invisible wall to stop player from going beyond), the path will end and mp_grid_path(...) will return false and therefore make it stop.

Any idea how I can fix this? Thank you so much!
 
Basically you want to create a new path only if there is a new path to be made.

I went to look up the functions needed and there is actually an example of what you need right in the manual under path_delete().
 
M

mzn528

Guest
Basically you want to create a new path only if there is a new path to be made.

I went to look up the functions needed and there is actually an example of what you need right in the manual under path_delete().
Thanks Strawbry_jam! I guess I am still a little bit confused, if there's already a path existing why would I use path_delete? I thought my problem is with the path terminating itself...?
 
Code:
var t_path;
t_path = path_add();
if mp_grid_path(grid, t_path, x, y, obj_Player.x, obj_Player.y, 1)
 {
 path_assign(mypath, t_path);
 }
path_delete(t_path);
Paths need to be deleted so they don't continue to take up memory. You need to run the path finding code on a temporary path so your current path is not destroyed. If a new path was made, keep and use the new path. If not, just destroy the temp path.
 
Top