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

Tips for smoother AI pathing?

Dreadusa

Member
Currently I'm using a basic grid system to create a path for all of my enemies, they all use the same grid but it's a bit jittery.

The path updates every frame to follow the player's X and Y coordinates, and the enemies move relatively fast to the player at a speed of 4 pixels per second while the player goes 5 pixels per second.

I'm sure there are many ways to approach this, but I was wondering what the best ways to do it would be. I've looked at the code of a few tutorials that use pretty much the same system and I'm looking for smoother ways to achieve pathing.

Thank you in advanced!

I'm using standard edition version 1.4.1772
 
Last edited:
C

CedSharp

Guest
Please explain what you mean by 'smoother'. Smoother as in the path should be less 'straight lines' and more 'curvy lines' ? Or does the object jitters while following the path ?
Maybe you can add a screenshot to visual what you are asking. We don't know about your game and can't guess what you're asking for unless you explain in great detail :)
 

Dreadusa

Member
Curves would be wonderful! That's the perfect way to put it
Here is a video that displays how it looks in game.
 

Dreadusa

Member
This is amazing! I'm really sorry if that was obvious to most people, I don't have much experience using game maker or programming in general but I want to learn how to.

You are amazing, thank you so much for the function.
 
C

CedSharp

Guest
This is amazing! I'm really sorry if that was obvious to most people, I don't have much experience using game maker or programming in general but I want to learn how to.

You are amazing, thank you so much for the function.
Note that this method will use the internal motion variables from gamemaker ( image_angle, direction, etc ).
If you have to modify those, you might see some weird results.
 

Dreadusa

Member
Well I'm tinkering around with this function and sometimes when my player is on one side of the wall and the enemy is on the other side of the wall, it starts going in circles until I move. Do you know what's causing this? If you need a video please just tell me, though I may reply late. I want to see if I can identify the issue myself.
 
C

CedSharp

Guest
Well I'm tinkering around with this function and sometimes when my player is on one side of the wall and the enemy is on the other side of the wall, it starts going in circles until I move. Do you know what's causing this? If you need a video please just tell me, though I may reply late. I want to see if I can identify the issue myself.
The mp_potential_step function is slightly limited. You would have to implement it yourself if you want to avoid that behavior. The problem is that when there is an obstacle, it calculates a new path, but only on a short distance. Motion Planning doesn't calculate a full path every step, that would be a waste of cpu. Instead it does a very small lookup around. Because of that, When it reaches the end of "the small path" it re-does a new lookup, sees that you are below, and move toward you. If the obstacle is too big, then what you see right now happens.

If you mix both together, you'll get some nice result tho. Use your current working grid-based path-finding, then apply motion to your object instead of blindly following the path. You'll get the best result, something between the two!
 
C

CedSharp

Guest
The mp_potential_step function is slightly limited. You would have to implement it yourself if you want to avoid that behavior. The problem is that when there is an obstacle, it calculates a new path, but only on a short distance. Motion Planning doesn't calculate a full path every step, that would be a waste of cpu. Instead it does a very small lookup around. Because of that, When it reaches the end of "the small path" it re-does a new lookup, sees that you are below, and move toward you. If the obstacle is too big, then what you see right now happens.

If you mix both together, you'll get some nice result tho. Use your current working grid-based path-finding, then apply motion to your object instead of blindly following the path. You'll get the best result, something between the two!
For example, you could use mp_grid_* scripts to build a grid, then generate a path out of this grid. This path would lead to the player instead of being just a little part. Then, you can use mp_potential_step to go from one point of the path to the other.
This way you avoid all the jitter effect. Just remember that every time the player moves, you have to update the mp_grid. Depending on how you do this, and how many objects use it at the same time, it can become quite heavy for your game.

Be careful when using stuff like path-finding, specially if you create a new path every step. Path-finding uses a lot of CPU ;)
 
S

Simmons

Guest
Similar topic here, but my scenario is that I want an enemy to be chasing my player object. So where ever the player runs, the enemy will update his path, to catch him. Ideally, the paths would make a little more sense as if it was someone trying to catch someone. Meaning, instead of moving perfectly around the edges of a collision/solid object in my room, but rounding the corners. Currently I'm using mp_potential_path(enemyPath, o_Player.x, o_Player.y, spd, 1, false);
And it's working pretty well, but again, i get more of a "computery" path of action from my enemy, instead of and "intelligent" one.
I'd love it if there was a parameter that would "bezier" the path, or "smooth" the interpolation between the points of the path it is building... is it based on the fact that it doesn't create a full path to my player, as stated in an above reply? Can i force a larger path check?

Thanks in advance!!!!
 
Top