Roguelike - NPC grid based movement

I played around some more. I used a player and target object. The pathfinder behavior works best when the origin and center point are both in the center. Both objects were 32x32

The pathfinder grid was setup to match it. 32,32 and an offset of 16 and 16.that centers the objects in the middle of the grid. I set it to allow diagonals bc that looks more natural.

Here are my events. I split the formula up just to make it easier to read and debug.

This seemed to work although I didn’t test it with obstacles. It helps if the obstacles are also aligned to a grid. As always, it’s always wise to check if a path was found and add something to handle failures.

See this post for more about aligning things to a grid.

https://forum.gdevelop.io/t/how-to-make-sprite-automatic-move-perfect-in-pixel/63812/4?u=keith_1357

2 Likes