Agent velocity isn't update stable with FollowerEntity

  • A* version: 5.3.3
  • Unity version: 2022.3.37f1

I followed TerrainRecast sample to moving my agent with FollowerEntity. My problem is the velocity isn’t stable, you can see the below image when I debugged the velocity value.


It is my code:

It’s the FollowerEntity config: (I set up all configs based on RecastTerrain sample)

I’m using A* pathfinding with Photon Fusion, this code is inside FixedUpdateNetwork() function (like Update). I don’t know why the agent velocity is changed too much like that. Please help me, thank you!

Can you try and see if doing this in Update causes issues? I understand that would not fix it, but I’m curious if it FixedUpdateNetwork() may be involved.

1 Like

Yeah It worked correctly :frowning: Hmm I have to used FixedUpdateNetwork() to sync correctly with other clients.

Not quite sure why FixedUpdateNetwork would interfere.
The FollowerEntity.velocity property just gets the value that was stored in the last simulation loop…

1 Like

The only thing I can think of is if FixedUpdateNetwork() is possibly setting velocity on multiple clients? Could there be something like that going on?

1 Like

I tested and when I set new destination and SearchPath() in FixedUpdateNetwork(), the agent moved a bit lag (like speed changed very suddenly), and if I use in Update(), it moved more smoothly.

No, in above case, it was only called from the host, didn’t have any client in that case.

Do the clients and host exhibit this behavior identically?

1 Like

Yes. because it is only called at the host and will be synced position and rotation to clients, so I think don’t have any problem about networking, just something wrong at FixedUpdateNetwork()

I have just updated the log to check about time of Unity and time of Photon network.

if(Agent.velocity.magnitude > 0) Debug.Log("Agent.velocity: " + Agent.velocity.magnitude + " - at time: " + Time.time + " - and Photon tick: " + Runner.Tick);

and below is the log of this code, so the time is update correctly at both Unity time and Photon time :frowning:


Whether have something wrong when I updated the new destination and call SearchPath() again?

Sorry for the wrong information, I don’t know why in the past It worked when I changed to Update(). I have just tested again and when I called the function in the Update(), agent’s velocity still return unstable value.
Below is my code and log screenshot, this function is only place that I modify agent destination and call SearchPath().


can you break down the line where you define rdPoint? What’s going on there?

rdPoint is a randomly selected point around the Character. The agent is a pet, always follows the Character using pathfinding. When the agent is far from the Character, a new random point around the Character is chosen as the destination. Then, the agent searches for a new path using SearchPath (I’m unsure whether calling SearchPath is necessary or if simply setting the destination is enough)
To avoid updating the destination too frequently, I’ve implemented a timer that updates the destination only every 0.5 seconds (when the agent is far from the Character).
You don’t need to worry about the Teleport function, as it is never called in my implementation. The function is only triggered when the agent is too far from the Character. However, since the agent’s speed is set high enough to ensure it never gets too far, Teleport is never used.

1 Like

That helps a ton in understanding, thanks :smiley:

So you don’t have to, it just means that the agent will calculate their path as soon as their destination is set. From the docs:

You can for example use this if you want very quick reaction times when you have changed the destination so that the agent does not have to wait until the next automatic path recalculation (see canSearch).

So, how about this; can you try debugging what desiredVelocity is in addition to velocity?

1 Like

Thank you for your support @tealtxgr !


It is the log with desiredVelocity. It looks great. What’s the different between velocity and desiredVelocity?

velocity is the finalized movement that the agent is actually moving, essentially what you see on screen while desiredVelocity is just, as the name suggets, how the agent wants to move, including gravity and local avoidance.

Speaking of, if you’re using local avoidance can you turn this off and see if it works then?

1 Like

Yeah I tried to turn off the local avoidance but It’s still not work.


Whether have something wrong with my AStarPath? My terrain is very large.

I doubt the graph is the issue, however it’s worth a try; I’d simply add another basic graph of a smaller size and simpler/default settings, then set your units to only traverse that graph and see how it goes.

I’m not 100% sure what the pipeline looks like internally going from desiredVelocity to velocity and couldn’t find it myself in the documentation. @aron_granberg would you be able to break down what happens between those two variables?

1 Like

Hi,
I have just tested in a smaller and simple terrain. The problem is still happen in this case, it is still unstable and has too different between velocity and desiredVelocity.
I have changed to Navigation and it still worked correctly.
It’s my config and log with the small terrain.



@aron_granberg Can you break down what different between velocity and desiredVelocity?

Hi

I’m still very confused as to why it works for you in Update but not in FixedUpdateNetwork.
The velocity property is written once per frame to an entity component. So it shouldn’t matter where you read it (as long as it’s on the same machine).
It’s calculated as the distance the agent’s transform moved this frame, divided by the delta time.