Making small adjustments after destination is reached

Hey everyone!

I’m working on improving a 2.5D RTS pathing system in my game, here’s an overview:

  • Units can be set to “Attack” mode which will set their destination to the enemy base and they’ll start moving towards it
  • Every unit has an awareness radius around it, so if it’s moving and it sees an enemy unity within it’s awareness radius, it will Lock onto that unit and make it the new destination
  • Once the unit gets within a distance that is equal to or less than the range of it’s melee attack, it will start attacking
  • When the destination is reached (close to the enemy unit), it needs to align itself on the Z axis to make sure that the attacks (A sword swing in this example) will hit the target

I’ve achieved that Z axis alignment by manually adjusting the z position of the unit gradually to be aligned and this has worked great for the most part but I’m starting to run into the limitation of this (somewhat) janky implementation namely when trying to lock the position of the unit in RVO then the aligning happens it leads to units ignoring the RVO and sometimes stacking on top of each other.

How can I solve this alignment problem in a way that maintain A* behaving as expected? Is there a way to change the definition of endReachedDestination to include Z distance?

Thank you in advance!

Hi

When close enough to the enemy unit, you may want to enable the ‘lock’ option on the RVOController. Do you do this? This will make all other agents treat that agent as stationary, and the agent itself will not try to move due to rvo influences.

You can also decouple the agent transform’s position entirely from the agent’s internal position by setting ai.updatePosition = false (and perhaps ai.updateRotation = false). This will allow you to move and rotate the agent in any way you want. You can find the internal agent’s position using ai.position.