Quantcast
Channel: Questions in topic: "quaternion.slerp"
Viewing all articles
Browse latest Browse all 133

How to avoid single direction rotation with Quaternions?

$
0
0
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.

Viewing all articles
Browse latest Browse all 133

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>