How to avoid single direction rotation with Quaternions?
void Update()
{
newDir = new Vector3(joystickDirection.x, joystickDirection.y, 0);
angle = Vector3.Angle(transform.forward, newDir);
Quaternion rotation = Quaternion.Euler(-angle, 0, 0);
rotation = transform.rotation * rotation;
transform.localRotation = Quaternion.Lerp(transform.rotation, rotation, turnSpeed * Time.deltaTime);
}
I try to make the object's forward direction slowly align with the direction of joystick unit vector. However, using quaternions has limited rotation in single direction, it is either clockwise or counterclockwise at all times. This causes unwanted rotations where objects rotates 345 degrees clockwise whereas it should have rotate 15 degrees counterclockwise. I would like to rotate the object over single axis. I would be glad if you can help me out.
Your answer
Follow this Question
Related Questions
How to Rotate Y axis of an Object toward virtual joystick direction 0 Answers
Rotate clockwise/counterclockwise using Quaternion.Slerp() 0 Answers
Draw a ray from a gamobject and keep direction of the ray relative to the gameobjects rotation. 1 Answer
How to make a 2D sprite rotate towards a specific point while facing perpendicular to the camera ? 1 Answer