GameMaker: Studio

GameMaker: Studio

View Stats:
DirectOrder Sep 13, 2015 @ 6:08pm
A* pathfinding question when path is blocked
I am using the natively supported A* pathfinding algorithm for my enemies:

------------------------------------------------------------------------------------------------
grid = mp_grid_create(0,0,room_width/32,room_height/32,32,32);
path = path_add();
mp_grid_add_instances(path,obj_wall,1);
mp_grid_path(grid,path,x,y,obj_player.x,obj_player.y,1) ;
path_start(path,movement_speed,"",1);
------------------------------------------------------------------------------------------------

It works wonderfully. The player can place walls wherever they like, and the enemies will always find the shortest path around them to get the player object.

However, my issue is, the player can place walls in a way that completely cuts off the path to the player object, and when this happens, the enemies just disappear.

Does anybody know the GML code to test if the path still exists, so if it doesn't, I can delete the last wall placed?

Psedo-code:

if path_exists = False {
//destroy last wall placed
}

or something like that?
Last edited by DirectOrder; Sep 13, 2015 @ 6:13pm
< >
Showing 1-4 of 4 comments
Daynar Sep 13, 2015 @ 7:20pm 
mp_grid_path(grid,path,x,y,obj_player.x,obj_player.y,1) returns true or false based on if the path can be done (I think). I would check it from the spawn point to the player base every time you place a wall and then if it returns false delete the wall.
DirectOrder Sep 14, 2015 @ 5:03pm 
Thanks so much Daynar - I'll give this a shot and let you know how it turns out!

EDIT: You were right - it returns false when the path becomes blocked. Thanks again!!! :)
Last edited by DirectOrder; Sep 14, 2015 @ 5:19pm
DirectOrder Sep 14, 2015 @ 5:44pm 
So.....now I have a new problem....

In an End Step controller, I test to see if the path is valid, and if it is not, I delete the wall that was placed last. This part works. However, in between the placing of the wall and the end of step test (while the path is invalid), the enemies get jammed up and disappear. I also tried this in a standard step event and the same thing happens.

I guess it would help to know why pathfinding objects get destroyed when the path becomes invalid so I can prevent that. Any ideas?

Maybe I have to find a way to test if the placement of the wall will break the path before the placement takes place, rather than placing it and trying to fix it on the back-end if it causes a problem?
Last edited by DirectOrder; Sep 14, 2015 @ 5:50pm
DirectOrder Sep 15, 2015 @ 7:05pm 
Never mind - got it figured out - finally!!!! :)
< >
Showing 1-4 of 4 comments
Per page: 1530 50

Date Posted: Sep 13, 2015 @ 6:08pm
Posts: 4