• 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!

GameMaker Enemy getting stuck at walls using mp grid path?

Rexzqy

Member
Hi fellow game makers,

I am trying to do a pathfinding for my enemy. However, they get stuck at corners of walls quite often. Below is my code:

GML:
if collision_line(x,y,target.x,target.y,obj_wall,false,true) = noone
            {
                if path_exists(path)
                {
                path_delete(path);
                }
                mp_potential_step_object(target.x,target.y,fspd,obj_wall);
            }
            else
            {
                if path_exists(path) = false
                {
                    path = path_add();
                }
                
                if mp_grid_path(grid, path, x, y, target.x,target.y, true) = true
                {
                    path_start(path, fspd, path_action_stop, false);
                    
                }
            }
I have set a static collision mask, and the grid is pre created:
globalvar grid;
grid = mp_grid_create(0, 0, room_width div 8, room_height div 8, 8, 8);

Any help is greatly appreciated!
 

Rexzqy

Member
Tried putting the

if mp_grid_path(grid, path, x, y, target.x,target.y, true) = true
{
path_start(path, fspd, path_action_stop, false);

}
into an alarm and delete the path_create, a little bit better but still gets stucked time to time.

Please help :(

EDIT: After i delete the mp_potential_step_object it seems to be working fine.. but is that optimized? Also I dont get why when mp potential step object is in the enemy gets stuck
 
Last edited:
Top