I'm using Unity 4, and I'm trying to orient my player camera with the surface normal of the ground they are standing on.
After calculating the ground normal, I am doing this:
var groundNormal = getGroundNormal(); var turnAngle = Input.GetAxis("Horizontal") * 2.25; var newRotation = Quaternion.AngleAxis(turnAngle, groundNormal); Quaternion.Slerp( oldRotation, newRotation, Time.deltaTime );
The quaternion will orient and rotate to the updirection partially, because the pitch and roll do not align perpendicular to the surface, like when we are on the default (0,1,0) ground normal.
I can maintain a perfect matrix transformation using a function called "ClipVelocity" that will reorient my direction vectors to be perpendicular to my ground normal, but I do not know how to translate this to quaternions.
How can I rotate in such a way that pitch and roll orient correctly to any plane orientation (for upside down loops, etc.)?
Edited by OneEyed, 24 December 2013 - 05:50 PM.