0
\$\begingroup\$

I'm currently using NavMeshAgent as my player character controlled by keyboard or gamepad input. Also, I'm flipping my character instead of turning via controlling localScale as below.

        private void FixHeadRotation()
        {
            float dir = (myAgent.velocity.normalized.x > 0) ? 1 : -1;
            transform.localScale = new Vector3(1, 1, dir);
        }

However, since I'm relying on the velocity I'm getting the direction(flip) right when moving, but not when I'm not moving(x should be -1 but 1 since no velocity).

I've noticed the NavMeshAgent has built-in function displaying an arrow gizmo over the agent's head. Perhaps I could use that(don't know how atm)? or any other suggestions to this?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I've solved this by simply conditioning my direction control within a velocity cap

private void LateUpdate()
{
    if (myAgent.velocity.x != 0)
    {
        FixHeadRotation();
    }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .