- Home /
How can I rotate an object with certain degrees?
I tried to rotate using;
Object.gameObject.transform.Rotate(new Vector(x,y,z));
and
Object.gameObject.transform.Rotate(x,y,z);
but whenever I use them object keeps rotating?
Answer by kolban · Apr 29, 2012 at 01:34 AM
Every time you execute the transform.Rotate() method, the object will rotate by the degrees around the given axis either in World or Local space. See the following manual page:
http://unity3d.com/support/documentation/ScriptReference/Transform.Rotate.html
The rotation will occur each and every time you call the function/method. If you are calling it within an Update() function, then it will rotate each and every frame. If you are not calling these statements directly in an Update check that you aren't calling them in a function which is itself called during the Update function. If you still are finding that the object is rotating and you are sure that you are not in an Update(), comment out the Rotate commands with the "//" comment code and run again. See if the object continues to rotate. It may be you have an animation associated with your object which automatically plays which includes rotation and the rotation has nothing to do with these exact statements.
I am trying to strech my knowledge about unity and c# script so wanted to create a simple cannon fight ai, so i wanted enemy cannon to have proper angle to hit player according to the distance between them. I thougt it must be done in Update() need to calculate the values dinamicly. I shall use a rotation function somehow then.
Answer by ProfArithmetic · Apr 29, 2012 at 02:51 AM
Rotate_flag = false; if(Rotate_flag) // rotate
That should do it. And then just change the flag whenever you want it to rotate
Your answer
Follow this Question
Related Questions
Get object rotation for x axis in degrees (360) 1 Answer
What is the most efficient way to rotate an object? 3 Answers
How to rotate object slowly on only Z axis 2 Answers
Rotation with multiple objects 1 Answer
Rotate a moving object 0 Answers