- Home /
Descent ship align z axis to underneath plane normal
I have a question that was asked before.
I implemented the following code into my spaceship:
RaycastHit hitInfo;
if (Physics.Raycast(transform.position, -Vector3.up, out hitInfo, 40.0f))
{ Quaternion rot = Quaternion.FromToRotation(Vector3.up, hitInfo.normal);
transform.rotation =
Quaternion.Slerp (transform.rotation,rot, Time.time * centeringSpringForce);
}
Right now, the code will align and recenter my Z axis to the normal of the polygon underneath my ship, but it also freezes my ships ability to be rotated in the other axis. It freezes my Y and Z rotation to 0 (or very close to 0), and perfectly locks my ship to the z value of the normal underneath my ship. I've been scratching my head for a little while now, do you have any ideas for what might be causing my ships X and Y rotation to be frozen at around zero?
Answer by robertbu · Nov 16, 2013 at 03:48 AM
Try the following change to how you calculate 'rot':
Quaternion rot = Quaternion.FromToRotation(transform.up, hitInfo.normal) * transform.rotation;
Consider also the order the scripts are run.
Your answer
Follow this Question
Related Questions
Rotating a character relative to the ground's rotation 1 Answer
unwanted rotation on the y and z axes 1 Answer
Fixing the rotation around a particular axis using Quaternions? 2 Answers
Rotate with raw gyro data. 0 Answers
(Solved) Aligning player to surface while still maintaining look direction 1 Answer