- Home /
Stopping a game object from spinning in Y axis.
I have a game object which spins in all the axes when i click on a plane. I want the object to stop from spinning on the Y axis because I am making a 2D game. Please give your valuable response as soon as possible. The code is...
function Update() {
// Look at and dampen the rotation
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime*damping);
}
Please help me soon. Thank you.
Answer by flaviusxvii · Mar 11, 2011 at 09:59 PM
The beauty of a Quaternion is that it will rotate on all axes to take the shortest rotational path from A to B. If you don't want rotation in an axis, you should just use transform.Rotate or change the eulerAngles directly.
Maybe this is helpful http://unity3d.com/support/documentation/ScriptReference/Vector3.RotateTowards.html
Thanks a lot for your answer :) it was really helpful. but.. can you provide me a sample code for that please ? i'm kinda new to Unity. Please do me this favor. Thanks again.