- Home /
How to reduce the rotation radius in NavMeshAgent ?
When the NavMeshAgent rotates (while going to a destination) , I want it to rotate in-place, or the smallest possible radius . but I can't find that in the Inspector, how can I achieve that ?
Answer by haliodoha7 · Oct 07, 2020 at 08:55 PM
Getting correct results with the built-in navmesh will be hard, because there's no way to make it have a turn radius. So you'll have to fake it - don't set the destination to be the player, but instead make it follow a set of waypoints that's the semi-circle you want it to move in.
or you could just ask for a navmesh path directly, and follow it without an agent.
In short forum: There's no way to do that unless you do it out-of-box Try reducing Speed ,@yahyouch36 Getting correct results with the built-in navmesh will be hard, because there's no way to make it have a turn radius. So you'll have to fake it - don't set the destination to be the player, but instead make it follow a set of waypoints that's the semi-circle you want it to move in.
or you could just ask for a navmesh path directly, and follow it without an agent. If you're doing that, Aron Granberg's A* project will be more suited to the job, as it's designed for that.
Answer by Darkc0re · Feb 19 at 11:38 AM
@yahyouch36 I had this exact same issue.. was driving me nuts.. made my character feel sloppy.. SO I found a solution using the navAgent in my code.
Initially, I had a partial workaround, when I had line of sight to the target location, I would do a manual rotation first and then let the NavAgent take over.. with NavAgent.isStopped == True until my rotation check was done and returned a true, then continue walking..
But after doing some research into how the NavAgent worked, I found that you are able to get the next movement location. navAgent.steeringTarget <-- this is the next point it will move towards, So I do a hard turn to this location and then let the navAgent walk.. so from sloppyJoe movement to snappy
So when I handle my click to move I set the navAgent.setDestination to click location, navAgent.isStopped = true, I pass "navAgent.steeringTarget" to the following function, which returns true if facing the correct way. at which point I navAgent.isStopped = false AND it continues the rest of the walk, after moving. you COULD have a check while walking, seeing if the movement angle for a turn is past a set degree and do a snappier turn :)
public bool RotateToTarget(Vector3 target)
{
Vector3 direction = (target - transform.position).normalized;
float dotProd = Vector3.Dot(direction, transform.forward);
if (dotProd < 0.9)
{
Quaternion lookRotation = Quaternion.LookRotation(direction);
transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, 0.25f);
return false;
}
return true;
}
Your answer
Follow this Question
Related Questions
Overlapping NavMesh area types makes it impassable for some agents 0 Answers
I can't get the manual Nav Mesh example to work. 1 Answer
CS0246: The type or name space name ''NavMeshSurface'' plz some help 0 Answers
Getting a navmeshagent back on a navmesh. 1 Answer
How do I get agents to avoid each other? 0 Answers