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

Motion Planning : mp_grid-

E

Emberex

Guest
Okay, I have this game where I need the "enemy" to move toward a target, then if there are no targets , move toward the player. I tried mp_potential_step, but they get weird around walls and sometimes won't find the opening. So I moved to trying mp_grid. In the page with mp_grid_path, it shows this code:

with (oZombie)
{
global.ePath = path_add();
if mp_grid_path(global.eGrid, global.ePath, x, y, oTarget.x, oTarget.y, 1)
{
path_start(global.ePath, 0, 3, 0);
}
}

I have changed some variables, but my issue is that the zombies won't even move, they just stand their. I know it's a simple problem, but I can't seem to find the issue. Any ideas?
 

Binsk

Member
Do you understand how the above code works? Debugging is much simpler if you understand how things work so that you can pinpoint what isn't behaving as expected.

mp_potential_step is basically 'reactionary'. It checks things for that step, tries moving, then forgets what it just did. Super simple but as a result it isn't very sophisticated.

mp_grid_path actually performs planning that will need to be carried out over multiple steps. This function generates a path (a GameMaker resource) that sketches how to get from the current position to the target position.

You can do whatever you want with this path. In the example given above, they use path_start. This is an automated system that will take control of the object and have it trace along the path that was calculated. Is that what you want? Do you have any other AI code that may be fighting against this?

You can also manually extract data from the path (such as point locations, length, and whatnot) and use it however you wish, namely programming your OWN follow code that works with whatever you may already have.

One last thing to note is that mp_grid_path won't always be able to find a path to the target. for example if all routs are blocked. In this case executing the path won't work at all and you should check for this.

Hopefully all this information can help you figure out the problem. If you simply can't do it give us some more details and perhaps what part of it you aren't understanding.
 
Top