A* Pathfinding Project

How to stop A.I. movement?


#1

Hello,

I’m trying to find a way to stop my RichAI from moving.
One way I figured this could be done is setting the seeker target to the gameobject itself, but I guess this is hacky since the UpdatePath will still be calculating.

I found a Stop() method in AIFollow but it says that one’s deprecated. I’m using RichAI, how do I properly stop my A.I. from moving?

Thanks


#2

Hi

You can simply set the speed to zero, or disable the component or set the target to the position of the character itself. Either one would work, however setting the target to the same position as the character may make it move forward a small distance until the new path is calculated.


#3

I thought about setting speed to zero but then won’t it keep recalculating paths anyway which would be suboptimal?
And disabling the component any time I want won’t cause any errors? (I presume not since you suggest it but want to make sure :slight_smile: )


#4

No I think that will work fine.


#5

alright, thanks Aaron!


#6

Hey guys,

Any idea when I trigger this code in my units when they were on their way to a target that died, they slowly float away still?

Debug.Log("No enemies in sight. Stopping movement...");
// Figure out how to stop movement here
speed = 0;
GetComponent<RichAI>().maxSpeed = 0;
GetComponent<RichAI>().enabled = false;`

I have an RVO controller on them as well.


#7

Not sure I can help at this point (I started using the plugin recently). I just set the maxSpeed to 0 when the melee enemy gets close enough and starts swinging the weapon and it seems to work fine.


#8

Hi

If you set RichAI.enabled = false then that will stop it from telling the RVOController how to move.
The RVOController in the latest release (this has changed in the beta however so this is no longer an issue) takes a velocity as input and it will continue to move in the desired velocity until something tells it not to. When you disable the RichAI component nothing tells the RVOController to stop so it just continues to move.


#9

Thanks Aron. I noticed the beta version is dated form a year ago and seems to not work as well as the newest normal version. Am I downloading the correct thing?


#10

Hi

Sorry for the late answer.
Yes, you are downloading the correct thing. There are a few fixes from the latest release that it is missing, but it is mostly ahead of the current release still.


#11

May I ask why there isn’t just a .Stop() or .Pause() method like Unity’s Navmesh system? I’m curious to know for the sake of comprehending the API decisions and proper use of this tool.


#12

@Disastercake

Sorry for the late answer:
In the latest beta I have done a major API overhaul of the movement scripts.
The resulting API has both many more features and is easier to use in my opinion. It is also designed to be very similar to Unity’s NavmeshAgent API to make it easy to get started for people used to that API (except in some cases where I have kept previous names for backwards compatibility).

In this API there is a property called isStopped which I think will do exactly what you want. When set to false the agent will immediately start to slow down as quickly as it can, however it will still react to local avoidance.
There is also another property (which has been in the system for a long time) called ‘canMove’. Setting that to false will disable movement calculations completely, which is useful in other scenarios.

Here is the documentation for the isStopped property.


#13

Hi Aron,

I’m sorry to revive such an old thread, but I don’t think that this adequately answers the question for anyone looking it up on Google.

I have a follow-up question about isStopped. As the documentation states, setting it to false doesn’t actually clear the path. It stops the characters fine, but, when I inevitably set it back to true, they start moving wherever they were moving before.

How do I reset the path? Setting AI destination to its current position causes movement back on the path which looks terrible – so that is clearly not the way. Setting speed to 0 has the same result as isStopped. I really need them to stop and forget where they were going.

Cheers,

Sergey


#14

Hi

If you want to clear the path you can use

ai.SetPath(null);
ai.destination = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);

Setting the destination to an invalid value prevents the AI from immediately recalculating a path to the target. You can alternatively set ai.canSearch = false to achieve this.


#15

Works like a charm! Thank you very much. My previous solution involved a bool that was tracking the fact that I’d stopped the characters – which I was very unhappy with. But this is great!