- Home /
 
               Question by 
               me136703 · May 23, 2020 at 11:16 AM · 
                rotationphysicsvector3quaternion  
              
 
              Game Object rotation sometimes doesn't match defined quaternion
I'm trying to set a ship to rotate to match a curved ramp and also to face forward as it moves around the ramp. I have a solution which I believe should work but at specific points on the ramp the ship rotation changes to completely different (but consistent) rotations.
The rotation is defined as below:
 RaycastHit hit;
 Physics.Raycast(transform.position, -(transform.up), out hit);
 Vector3 forwardDir = Vector3.Cross(transform.right, hit.normal);
 Debug.DrawRay(transform.position, forwardDir, Color.blue);
 Debug.DrawRay(transform.position, hit.normal, Color.red);
 Quaternion newLook = Quaternion.LookRotation(forwardDir, hit.normal);
 transform.rotation = Quaternion.Slerp(transform.rotation, newLook, 0.05f);
Does anyone have any idea why the ship might rotate like this sometimes:
 
                 
                screenshot-3-min.png 
                (295.2 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Slerp to make the right/left side face another object 2 Answers
Rotate vector3 relative to another vector3 1 Answer
Rotating wrong 0 Answers
Aiming to gameobject 2 Answers
How do you rotate an object with Vector that has another vector defining its angle 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                