,Snap rotation relative to rotation
I'm trying to snap the rotation of my player according to its rotation in 90 degree increments
For example, if I'm facing forward in the scene, 0 Rotation on the y, I want my character to snap to 90 Rotation on the y if it moves to the right.
But if my character is pointing at 45 Rotation, I want the snapping to take that into account, and instead of snapping to 90, I want to snap it to 45+90, or 135 degrees. Right now, if I'm pointing at 45 Degrees, my character will snap to 90. ![alt text][1] [1]: /storage/temp/169225-2.png Help please?
Answer by streeetwalker · Oct 14, 2020 at 06:34 PM
To add two rotations, multiply their quaternion representations. So, in pseudo code:
Quaternion deg90Rot = Quaternion.AngleAxis( 90, transform.up )
Quaternion currentRot = transform.rotation
transform.rotation = currentRot * deg90Rot
the fist line of code can be stored as class variable and calculated in Start, because you'll probably use it over and over.
Ahh that was probably why it was acting weird, I was using eulerangles. Thanks a bunch!