I’m using a NavMeshAgent on a 3D object that is rendered as a 2D sprite. Because of this, I don’t want it to rotate; I simulate rotation by changing the sprite.
However, I’m getting unexpected values that cause the sprite to be facing the wrong direction. Here’s a snippet of my code.
private void Update() {
_agent.updateRotation = false;
}
private void FaceInDirection(Vector3 destination) {
Vector3 direction = (destination - transform.position).normalized;
Debug.Log("Direction: " + direction);
_animator.SetFloat("X", direction.x);
_animator.SetFloat("Y", direction.z);
if (direction.x < 0) { _renderer.flipX = true; } // Moving Left
if (direction.x >= 0) { _renderer.flipX = false; } // Moving Right
}
From the debug statement, I can see the issue: regardless of which way it’s moving, the X values are coming up negative. What should I be checking to know if I should flip the sprite?