GMS 2 How to check for an unobstructed path.

hans

Member
Hello, is there a way to see if an instance has an unobstructed path to a specific instance. I'm currently trying to implement an enemy spawner that first checks to see if the enemies it's spawning are able to travel to the player before spawning enemies.
 

Rob

Member
It depends on how you're doing the path. if it's a straight line you can use something like collision_line.

Code:
obstacle = collision_line(fill in the entries)
Obstacle would hold either an instance ID or noone.
 

hans

Member
Not exactly, i'm trying to see if a path is possible from the spawner object to the player object, and if there is no possible path to not spawn enemies. This would have to be able to circumnavigate a maze like structure.
 

Catastrophe

Member
Basically, set up an mp_grid, and then use mp_grid_path. If it returns false, you've got no path. An alternate is an A* extension.

Sidenote: If you're using this method, you may as well use it for your actual pathfinding as well.

But yeah pathfinding a maze will require a bit of setup like this.
 
Last edited:
Top