Jump to content
  • Advertisement
Sign in to follow this  

Quaternion Rotation along plane surfaces (maintaining Pitch/Yaw/Roll)

This topic is 2120 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



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

Share this post

Link to post
Share on other sites
The question is not completely clear to me, but if what you are trying to do is take a particular rotation and find the "closest" rotation to it that sends the vector (0,1,0) to the normal of the surface, you can do that by using the formula in this stackoverflow thread.

EDIT: The way you would use that formula is to compute where (0,1,0) is being mapped to by your current rotation, then use the formula to compute a rotation that maps that vector to the surface normal, then modify the current rotation by composing in the computed rotation (in whatever order it has to be done). Edited by Álvaro

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!