Finish Moving to Next Cell before Changing Path

  • A* version: 4.2.18 (Pro)
  • Unity version: 2021.3.24f1

Hi,

I posted a year ago and my problem was solved (thank you). I am still working on the same RTS game using unfiltered AILerp to make units obey the grid while moving in real time. This has been working pretty well so far (using tag manipulation to prevent collisions), but I have a new problem that I haven’t been able to solve.

Paths will always obey the grid (so that legs of the path always face one of eight directions) except for one circumstance: when the player issues a move order to a unit that is currently moving, it will immediately calculate a new path and start it. This allows the unit to briefly move outside of the grid as it moves to the first cell in the new path, causing odd path legs like the one seen to the left.
Screenshot (288)
The best solution to this would be for the unit to finish moving to the next cell of the old path before starting the new path. I thought that this could be done by somehow removing all of the nodes from the old path except for the next one and then adding the new path after this. I believe that would be a robust system that allows the units to react quickly to new orders but also stay within the grid system.

I don’t know how to implement this in A*, so I would love any assistance. I figure I could wait for the unit to reach the next cell of the old path and then start the new path, but I don’t know how I would detect that it has reached that cell. So I suppose the key question would be how do you shorten the current path to only the next cell/how do you detect the arrival at the next cell (that isn’t necessarily the true end of the path)?

Thank you for your time.

Hi

I’d recommend changing Seeker -> Start End Modifier -> Start Snapping to Connection and End Snapping to Node Center.
See also AILerp - A* Pathfinding Project