Unity NavMeshAgent snapping

Hi all

Is there a way I can have it so the calculated path points snap to grid? I basically have a tile system and would like the waypoints to be snapped so it aligns if possible.

Thanks all

You could just set the destination to be closest point in the grid.
Maybe by rounding the coords, or checking which point is the closest to the given destination.

Hi thanks for that, I do set the destination as snapped however its the “corners” of the path that are not snapped.

Corners of the path?
I don’t understand, please elaborate.

Please forgive my very bad drawing but it may explain :slight_smile: The red is the player, the green is an obstacle, dark blue is the target.

Now when I click currently on the target the player will follow a path similar to the pink line however I need it more strict and tile based like the light blue line if possible.

1 Like

This explains it very well, thanks for drawing it!
So you want a tile system like RuneScape has.

I don’t think it would be smart to use the NavMesh system for it,
but I can’t really think of another solution to do this tbh.

This is how I’d do it:
First set the destination to the desired location.
Now check the NavMeshAgent’s path(or check the agent’s velocity),
you’ll know which direction it’s walking towards with that. Set the destination to the closest tile in that direction.
Everytime it reaches a tile, you repeat this process, until it reaches the tile that’s the closest to the destination point.

Hey thanks that’s a good idea, I will give that a shot! many thanks.

1 Like

please, I need to know if it worked

Please don’t necro post, it’s very unlikely that someone is going to remember this from 10 years ago.
Thread locked