Navmesh agent remaining distance wrong when movement done by root motion of Mecanim?
I have an enemy agent (navmesh), who is supposed to go to a destination. However I have turned his navmesh update position off.
agent.navMeshAgent.updatePosition = false;
I am turning the corresponding anim float variable at this point to invoke the movement(root motion is ticked on my animator component).
And this is my stopping condition.
if (agent.navMeshAgent.remainingDistance <= agent.navMeshAgent.stoppingDistance && !agent.navMeshAgent.pathPending) {
// do stuff like attacking etc
}
The problem is that the destination that I have specified before is far away(lets say z = 100), but the navmesh stops before even reaching say z = 30 or something. I think its because I am using mecanim movement and the navmesh agent thinks that its moving at its own speed and thereby when it reaches z = 30, it thinks that it has reached z = 100. So how do I sync navmesh speed and mecanim movement speed?
Answer by Cuttlas-U · Apr 11, 2017 at 09:03 AM
hi; try to not use remainingDistance and use Vector3.Distance to find the distance between your position and the target your self;
if ( Vector3.Distance ( transform.position , target.position ) < 1)
Your answer
Follow this Question
Related Questions
How to get a list of the closest distance targets with NavMesh. 0 Answers
nav mesh agent problem, can only be called on active agent that has been placed on a nav mesh 1 Answer
SetDestination doesn't work after building (with images) answer please 0 Answers
Let specific NavMesh Agents ignore some Area costs 0 Answers
How can I make it possible for a navemeshagent to walk trough terrain trees? 0 Answers