Hello!
Does anybody spot any error in my code?
To me it looks really beautiful and correct, but since my character doesn’t rotate towards the nextPosition, I think my code isn’t as good as I think. :-8
Does anybody see my mistake?
Thank you very much!
I have _agent.updatePosition = false;
void Start()
{
(...)
_agent.updatePosition =false;// I don't want the agent to actually move the rigidbody...
_agent.updateRotation = true;// ... I only want to know the direction in which the agent would rotate in order to follow the path
}
void Update()
{
_agent.nextPosition = _rigidBody.position;//doesn't work in FixedUpdate
}
void FixedUpdate()
{
(...)
pRotateTowardsNextPathPoint();
}
private void pRotateTowardsNextPathPoint()
{
//let the navmesh agent determine the rotation
//the position / velocity comes from the animation's root motion
//my animation forward velocity isn't linear, but NavMeshAgent only supports linear Speed, so I don't let NavMeshAgent move my character forward
var qTo = Quaternion.LookRotation(_agent.nextPosition);
qTo = Quaternion.Slerp(this.transform.rotation, qTo, 30.0f * Time.deltaTime);
_rigidBody.MoveRotation(qTo);
}