- Home /
Issue when freezing Quaternion rotation in one axis?
Hi,
how can i freeze the rotation to an axis so that the character does not bend over to look at his target?
I have tried to copy the character's rotation in y or z, but the result is not what i would expect:
This is the wrong result : (the character is bending over)
42 42
42
 var rot : Quaternion = Quaternion.identity;
 
 //in UPDATE
 var dir : Vector3 = vectorEndPoint - thisTransform.position; //vectorEndPoint = the ball; thisTransform = the character
             
 rot = Quaternion.LookRotation( dir ); 
 rot.eulerAngles.z = thisTransform.rotation.z;    //y or z        
 thisTransform.rotation = Quaternion.Slerp( thisTransform.rotation, rot, Time.deltaTime * 5 );
//or this way :
 var dir : Vector3 = vectorEndPoint - thisTransform.position;
 
 //TEST        
 thisTransform.rotation = Quaternion.Slerp( thisTransform.rotation, rot, Time.deltaTime * 5 );
 thisTransform.localEulerAngles = new Vector3(thisTransform.localEulerAngles.x, 0, thisTransform.localEulerAngles.z);
Would you know you to achieve this?
Thanks
SOLUTION:
 var newRotation = Quaternion.LookRotation( dir );
 newRotation.x = 0.0;
 newRotation.z = 0.0;
 thisTransform.rotation = Quaternion.Slerp( thisTransform.rotation, newRotation, Time.deltaTime * 5 );
What did you search for? "Unity look axis" came up with this:
http://answers.unity3d.com/questions/54973/rotate-an-object-to-look-at-another-object-on-one.html
@OwenReynolds argh sorry, i did look at some topics but i did not find any answer, but indeed you're right, this link is great, thanks a lot for your answer Owen
Answer by Pauls · Nov 23, 2012 at 10:08 PM
Thanks Owen for the comment, here is the solution :
             var newRotation = Quaternion.LookRotation( dir );
             newRotation.x = 0.0;
             newRotation.z = 0.0;
             thisTransform.rotation = Quaternion.Slerp( thisTransform.rotation, newRotation, Time.deltaTime * 5 );
Your answer
 
 
             Follow this Question
Related Questions
How can I instantiate a gameobject facing another gameobject 2D? 0 Answers
Turret rotation with a pivot? 1 Answer
Look rotation makes sudden changes 1 Answer
Flip over an object (smooth transition) 3 Answers
Issues with rotation at 180 degrees 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                