- Home /
Rotating to -forward goes upside down
I'm probably missing something simple but I'm trying to turn the character around. Rotating to -transform.forward makes him rotate upside down.
Quaternion r = Quaternion.LookRotation(transform.forward, -transform.forward)
r *= transform.rotation
Rotating to transform.right twice works but is there a way to get the above to work?
Answer by Berenger · Jan 29, 2013 at 12:18 PM
There is an infinity of possible rotation to do that, Unity had to pick one. Try Quaternion.AngleAxis instead.
Quaternion r = Quaternion.AngleAxis(180, transform.forward);
transform.rotation = r * transform.rotation;
Quaternion.AngleAxis is causing Unity to crash so I guess I'll be sticking to rotating to .right twice.
Okay, crashing was my bad. AngleAxis also rotates upside down so no go.
If you want the character to turn around, you need to use the Vector.up for AngleAxis, not forward, assu$$anonymous$$g you're nor simulating something special where (0,1,0) isn't pointing up.