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.
↧