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

GML Unreachable pathfinding mp_grid_path

zampa

Member
Hi, i'm working on pathfinding for my enemies using the a* system, i created a grid and added all tile instances for walls and pits in the room and i encountered a problem let' say i put a platform surrounded by pits that the player can access, i that case the function mp_grid_path would return false and the enemy would not move, but givven that the is no wall blocking sight for the enemy i would like him to move towards the enemy.

Here are some ideas i came up with to solve this
1) just don't add the pits tile instances to the grid and stop the enemy when he approches a pit (i do not think this could be usefull because it would not help with avoiding said pits)

2) in the case that the player is unreachable start a while cycle that checks for reachable spaces within the line of sight between player and enemys

Are any of these valid solutions? Or is there another easier way

Thank you
:)
 
Your explanation is really confusing, I'm assuming that what you mean is that when an enemy is unable to reach the player through the mp_grid_path function (i.e. it is surrounded by impassable spaces), it should still move towards the player to the closest point it can reach.

I don't actually use the built in mp_grid functions (usually code my own A* for more flexibility within the system) but looking through the manual, what I would do is this:

1. Check to see if a path can be found from the enemy to the player.
2. If a path is found, follow that path.
3. If a path is not found (i.e. the enemy is surrounded by pits), then start using mp_potential_step or mp_linear_step to move towards the player. This should ensure that even if a full path from the enemy to player can't be found, it will still move towards the player as far as it can.

Btw, in your option #2, you would most definitely NOT use a while loop to "wait" for reachable spaces. A while loop will not let the next game step execute until it has completed. This means that if it's checking for a condition that can't be satisfied inside of it's block, it will freeze your game completely. Read this: https://forum.yoyogames.com/index.p...p-structures-vs-step-checks-and-alarms.39941/ helpful tutorial on when you should be using loops vs alarms, etc.
 
Last edited:

zampa

Member
Your explanation is really confusing, I'm assuming that what you mean is that when an enemy is unable to reach the player through the mp_grid_path function (i.e. it is surrounded by impassable spaces), it should still move towards the player to the closest point it can reach.

I don't actually use the built in mp_grid functions (usually code my own A* for more flexibility within the system) but looking through the manual, what I would do is this:

1. Check to see if a path can be found from the enemy to the player.
2. If a path is found, follow that path.
3. If a path is not found (i.e. the enemy is surrounded by pits), then start using mp_potential_step or mp_linear_step to move towards the player. This should ensure that even if a full path from the enemy to player can't be found, it will still move towards the player as far as it can.

Btw, in your option #2, you would most definitely NOT use a while loop to "wait" for reachable spaces. A while loop will not let the next game step execute until it has completed. This means that if it checking for a condition that can't be satisfied inside of it's block, it will freeze your game completely. Read this: https://forum.yoyogames.com/index.p...p-structures-vs-step-checks-and-alarms.39941/ helpful tutorial on when you should be using loops vs alarms, etc.
Thanks, sorry for the sloppy explanation, I will what you suggested
 
Top