- Home /
How can I stop Navmesh agent sliding?
I recently tested the Navmesh feature if Unity 3.5, right now I have character with a rigid body and one without, both have Navmesh agents and I've tested them both, but when at high speeds they tend to slide past the target and never reach the stopping distance. The rigid body is not causing this so, how can i stop this sliding?
Answer by Evil_Gia · May 16, 2012 at 02:32 AM
Try setting the acceleration to be a high number such as 60. Note that navMeshAgent stop its force at that location but will still move forward due to inertia. A high acceleration will make it stop very close to that exact location
I was looking for this for a couple of days, the agents were sliding on my target before stoping, This fixed it with an acceleration of 100
Answer by darrelcusey · Jun 18, 2015 at 01:17 AM
I'm seeing that this is STILL an issue in Unity 5. For anyone who is still experiencing this issue, here is a solution that works for me:
public float acceleration = 2f;
public float deceleration = 60f;
public float closeEnoughMeters = 4f;
private NavMeshAgent navMeshAgent;
void Start()
{
navMeshAgent = gameObject.GetComponentInChildren<NavMeshAgent>();
}
void Update()
{
if (navMeshAgent)
{
// speed up slowly, but stop quickly
if (navMeshAgent.hasPath)
navMeshAgent.acceleration = (navMeshAgent.remainingDistance < closeEnoughMeters) ? deceleration : acceleration;
}
}
Answer by nonopblic · Jul 22, 2017 at 07:50 AM
in my case, setting acceleration to 60 does not work. so i have to create another solution like this.
if (Vector3.Distance(target, transform.position) < navMeshAgent.stoppingDistance)
{
navMeshAgent.SetDestination(transform.position);
}
else
{
navMeshAgent.SetDestination(target);
}
Answer by jolta · Jan 10, 2018 at 08:21 AM
I got the Same Issue but my character was slipping while turning. This works for me. Increase "Acceleration" and increase "Angular Speed". Values for my Character Speed=30 Angular Speed=300 Acceleration=140
Your answer
Follow this Question
Related Questions
Rigidbody gain speed falling on slope 0 Answers
rotation problem 1 Answer
RigidBodies vs CapsuleCasts 0 Answers
Collision If Statement And Falling throught the ground (2 questions) 1 Answer
Make an object increase speed when entering trigger 2 Answers