- Home /
Removing 100ms Delay in NavMeshAgent moving to destination?
After setting the destination & unstopping the NavMeshAgent
myNavMeshAgent.SetDestination(targetposition);
myNavMeshAgent.isStopped = false;
And the actual character moving (changing position)
if (transform.position != startingPOS)
{
Debug.Log("Position Changed: ElapsedMilliseconds: "
+ MasterWorld.stopWatch.ElapsedMilliseconds);
}
There is a 100ms delay. This creates significant input lag. Unacceptable. However, I would really like to keep navMeshagent.UpdatePosition = true (not have to create my own system to handle movement).
Is there a better method to use to start movement, other than .isStopped? I would like movement to start instantly, not 100ms after isStopped = false. Preferably without having to manually handle everything in code myself (only using NavMeshAgent to determine path.)
Answer by CarterG81 · Oct 10, 2017 at 10:30 PM
The delay was caused by SetDestination() taking too long to calculate the path.
I didn't think this would be the answer, since the path was extremely simple (straight line, no obstacles).
So this input lag is not avoidable (unless I'm generating my navmesh incorrectly).
Instead, I'll need to add some predictive movement. By keeping UpdatePosition = true, my custom movement code will still remain in the limits of the navmeshsurface. So I can just start moving the character.
Something like a coroutine...
while(myNavMeshAgent.PathPending)
{
ImmediatelyMoveToDestination() //Manually move character
}
//When Path has finally been calculated
myNavMeshAgent.IsStopped = false; //Or just stop manual movement & allow automated pathfinding to take over
This seemed to be impossible to fix.
myNav$$anonymous$$eshAgent.PathPending would report false, when it was still true. Falsely reporting would result in random input lag (whenever it falsely reported) while it my predictive movement method was called if it was correctly reported.
Your answer
Follow this Question
Related Questions
Unity Navagation Ground Mapping 1 Answer
Duplicated NavMesh Agents not moving 0 Answers
NavMesh agent snaps to wrong mesh 0 Answers