How to make two objects run towards each other and stop at the correct spot?

I’m making an RTS or MOBA style AI that will need to run up to other players and enemies and stop correctly. If I rely on just the path with endDistanceReached set to stop when say, within 1 units, they still end up running into each other if their movement speed is high enough.

I understand that this is because the path isn’t updated in time. So I set the path to update more frequently but the problem occurs if the movement speed is high.

So, what can I do to fix this? Do I need to make my own movement script and take the velocity of my target into account and shorten the path accordingly? Should I just add distance checks each frame and hard stop the RichAI/RVO Controller movement completely? I was really hoping to avoid needing to add any colliders and rigidbodies because it messes with the RVO controller.

I don’t have an issue trying these solutions, I’m just wondering which approach works and scales the best later down the road.

Here is an example with endDistanceReached set to 1 and the max speeds of the objects set to 5: https://imgur.com/a/PSjnVgH. Notice how they run into each other (I turned the RVO controllers off for this example). In this case I’d need to manually tune endDistanceReached for each object by knowing the other’s velocity which is tough.

Am I over thinking this?

Hi

When the endReachedDistance is reached the agent will start to slow down. It will do so with the maximum acceleration configured on the agent, but it may still take a few frames for it to reach a full stop.
For an RTS you may want it to stop completely in a single frame, in which case you can use

ai.enabled = false;

Or if you are using the beta version you can alternatively use:

ai.desiredVelocityWithoutLocalAvoidance = Vector3.zero;
ai.SetPath(null);
ai.destination = ai.position;

Which has the benefit that the movement script is still running, which you may want for local avoidance purposes or something else.

Thanks, I’ll think about these for implementation. Is there any problem with toggling CanMove on or off as well? Either way, I definitely want the RVO controller to continue working so that units aren’t walking inside each other.

Hi

If you are using RVO as well then you could just enable rvoController.locked. That will inform the local avoidance system that the unit cannot be pushed around by other agents which helps somewhat.

If you are disabling the movement script component then enabling/disabling canMove doesn’t do anything really. The component is disabled so nothing in that component will run.

I guess what I’m wondering is how often do people literally just straight up disable or stop using the pathfinding movement? I don’t see a solid way forward without doing a mix of a my own “normal” ai/movement script along with the pathfinding components.

Fore example, just getting to a point and then deciding what to do with the player… I don’t want the pathfinding working at that point, right (well, maybe RVO)? I don’t foresee myself literally making a movement script using the pathfinding core code myself either.