Any way to stop snapping when recalculating a path?

  • A* version: 4.2.17
  • Unity version: 2023.2.22f1

Making a game that involves bridge building with enemies that need to pathfind around the player’s bridges. If the enemies get trapped, instead of just trying to push their way out or stopping movement, they snap to a grid line and cause this weird interaction. Any way to work around this?

Hey there sorry for the delay- I’m assuming you mean the part where they “ram” their way out of the box? That’s what you’re trying to prevent?

Can you record a video showing their path and the navmesh?

Yes, that’s what I was referring to. The graph is updated every 30 ticks with this script, which seems to be when the snapping occurs.

Never seen this myself. Are you in a position to send over this project so I can toy with it and figure out the best way around this?

I think I’ve figured out what the specific problem is, just not the best way to fix it. When the grid gets recalculated every 30 ticks, the enemies will sometimes be inside what the graph considers obstacles (since the grid size is larger than the enemies for performance reasons). If this is the case, then the enemy gets pushed out immediately from the obstacle which causes the motion in the video. The solution to this would be to make the “obstacle” parts of the graph only have a high negative preference, instead of being completely impassable, but I’m not sure how to do this. Also not sure if it would be a graph modification or a change I need to make on the seeker/AIPath component side.

You’ll wanna take a look at tagging:

Thanks, was able to solve it with this. For anyone wondering, the easiest solution for me ended up being to just add these two lines near the end of RecalculateCell() in the GridGraph class:

node.Penalty = node.Walkable ? 0u : 100000;

node.Walkable = true;

1 Like