More than 1 AI using AILerp in Grid graph, can they avoid each other as they move?

so I am setting up a system in 2D where there will be more than 1 gameobject using AILerp to move around and potentially they may cross paths, is there a configuration where they will avoid each other?

for context the gameobject will have a boxcollider2d, seeker, AILerp and AIDestinationSetter component and using a GridGraph with “use 2d physics” checked and collision testing checked

update: i read that AIlerp doesn’t support local avoidance so maybe i need to add custom local avoidance?

Hi

AILerp is not designed for any kind of local avoidance.
You need to use another movement script. For example, the FollowerEntity component.

1 Like

so i tried FollowerEntity and i have 2 questions:

  1. Rotation Speed: I don’t need the entity to rotate but if I set this to 0, it seems movement speed is also impacted. Is that expected behavior? If i set Rotation Sync to “Rotate independently of transform” then it doesn’t rotate but the speed value still needs to be set for the entity to actually move

  2. is it possible for the entity to still move grid to grid (like in AILerp)? right now its moving fluidly which is cool but not exactly what we are aiming for

thanks

Yes. The FollowerEntity always uses some rotation internally. If you want it to behave as if not using rotation at all, then set Rotation Sync to Rotate Independently of Transform, and set Rotation Speed to Infinity.

Not really, I’m afraid. The FollowerEntity is not built for that kind of movement.

It sounds like what you want is cooperative pathfinding. But this is not included in this package, I’m afraid.

1 Like

ah ok… 1 last question, using FollowerEntity with local avoidance turned on, is there an event that I can detect when the original path has changed to be triggered? so in my example i click on something and the entity moves towards it. i want to track if it has detected something and changed from its original path. Is there something that i can detect now?

update: i am getting the list of nodes in GetRemainingPath and then comparing the number of nodes each frame and if there are more, it means path has changed. not ideal but some basic indication that path has changed

Hey there,

You might want to check out the AvoidingAnyAgents property. You could check when this value becomes true and fire code based off that. :+1:

UPDATE:

I went to double-check this, because I felt kinda fishy about it after I thought about it for a few minutes. FollowerEntity actually doesn’t have the AvoidingAnyAgents property (as far as I could find), however, you could also use desiredVelocity and desiredVelocityWithoutLocalAvoidance basically the same way. If those two values are the same, then local avoidance is not actively influencing the unit.

1 Like

hmmm comparing the values doesn’t really give an accurate representation. even if the entity is moving in a straight line with no interference, the values are not the same

It’s not working on your end? I just set it up myself using the following code, and when my unit was near other units, the delta between the two variables was more than zero. Otherwise, it stayed zero. Here’s the code I used:

FollowerEntity followerEntity = GetComponent<FollowerEntity>();
Debug.Log($"Delta between two variables is {Vector3.Magnitude(followerEntity.desiredVelocity - followerEntity.desiredVelocityWithoutLocalAvoidance)}");
1 Like

ah magnitude… i just compared the 2 values directly…

hmmm even if my unit is not really “near” other units it also triggers (> 0)

for your values for followerentity, what are they set to? maybe the configuration or local avoidance values for mine are too sensitive or something

Here’s my entire FollowerEntity as it is now:

If you have a bunch of units or obstacles all over the place, this method may not work for you, however what you could do, is define a minimum threshold, and once the delta goes over that, you can fire your code then maybe? It’s kinda hacky, but honestly it just depends on your needs- that could be a viable solution possibly!

hmm i wonder if becos mine is 2d its different. and yea potentially we may have a lot of entities. obstacles wise its simlar to what we can see in the example scenes

If you’re checking for “more than 0”, I can see how checking magnitude may not cause a desirable outcome. Is checking for more than, say, “.5” or “1” an option? So that way you can fire code if the delta is too large, rather than exists at all?

yea i adjusted a bit and will probably do something like that…

i was just hoping there’s some onchangepath event that i can subscribe to :slight_smile: