Legacy GM [SOLVED!] Pathfinding stop when surrounded

Hi everyone o/

I'm coding a top down game where enemies follow the player if they're close enough to it. I'm using this code:
if IsFollowing = true
{
if haveGrid = false
{
grid = mp_grid_create(0,0,room_width/32,room_height/32,32,32)
path = path_add()
mp_grid_add_instances(path,obj_Solid,true)
haveGrid = true
}
mp_grid_add_instances(path,obj_Solid,true)
mp_grid_path(grid,path,x,y,Target.x,Target.y,true)
path_start(path,Spd,"",true)
}
else
{
path_end()
}
this works pretty fine, but when an enemy with this code is surrounded by walls and have no possible path to follow, it just disappears! My game'll have some places, like fences/walls where some enemies'll be placed inside.
Like this:
upload_2019-12-1_21-54-51.png

How could I define, like, if this enemy is surrounded by the obj_Solid (which is my wall obj.), it ignores the Target and sets the "IsFollowing" variable to false?
 

TailBit

Member
from the 10th line
Code:
// mp_grid_add_instances(path,obj_Solid,true) // this line tries to treat the path as a grid, and you have already added the walls to the grid
if( mp_grid_path(grid,path,x,y,Target.x,Target.y,true) ){ // this returns if the path can be completed or not
    path_start(path,Spd,"",true) // "" should be: path_action_stop
}else{
    IsFollowing = false
}
 
Top