Ok I am having a problem with rotating the Z axis of my player to face towards his movement.
Here is my code - note that my object is oriented with Vector3.up being his “front”:
desiredAngle = Vector3.Angle(Vector3.up, rigidbody.velocity);
if (dir != Vector3.zero)
{
if(dir.x > 0.1)
{
desiredAngle = -desiredAngle;
}
transform.eulerAngles = new Vector3(0, 0, desiredAngle);
}
Now this works properly as far as the object facing as it should, problem is that when the player faces “negative desiredAngle” then the rigidbody “jerks” for only about 1 frame as it starts to turn to the right. This is ugly, and has got to have a better solution. Maybe a different way to calculate the angle, that wraps all the way around to 360 degrees, instead of just calculating the closest angle to a vector.
Or maybe I could do some smoothing somehow that would make the transition between a negative value for desiredAngle, and positive value, not noticeable? Rather than really twitchy when it switches over