- Home /
Rotate A NavMesh Before Moving
I am working on basic click to move kind of game I have movement working find, but I'm having a minor issue I'm stuck on. I can not get the navAgent to rotate towards the hit position before moving. Instead it this slow rotation while the navAgent is moving towards the destination.
I tried transform.lookat but instantly rotates to the direction, but I'm trying to get a slow rotation.
Can someone help me with getting the navagent to slowly rotate to the hitpoint before moving?
void PlayerMovement() {
// RaycastHit hit;
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float remaingdist = navAgent.remainingDistance;
if (Input.GetMouseButtonDown(0) && navAgent.remainingDistance == 0)
{
if (Physics.Raycast(ray, out hit, 100))
{
// Debug.Log("The hit point is " + hit.point);
navAgent.SetDestination(hit.point);
}
}
//
if (navAgent.remainingDistance > 0)
{
Anim.SetFloat("Speed_f", .26f);
}
}
Thanks for any help in advance.
Answer by Injec · Apr 27, 2017 at 01:42 PM
Hey, Maybe you can try to disable the navAgent rotation first.
navAgent.updateRotation = false;
Then you need to steer the rotation by yourself. I'd try to lerp towards you destination, and only after that let your agent move towards it.