- Home /
Problems with rotation script.
I have used this script, i don't get any errors but its not working. And i have set the rotSpeed even to 200!
var rotSpeed : float; var plane : Transform; function Start () { }
function Update () { if(Input.GetKey(KeyCode.LeftArrow)) { plane.transform.eulerAngles.y -= 180; } }
Answer by Tim-Michels · Jul 04, 2012 at 07:00 AM
You should rotate this way:
void Update()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
plane.transform.Rotate(Vector3.up, Time.deltaTime * rotSpeed);
}
}
The Vector3.up is the axis you're rotating around. The rotSpeed is the variable that determines the speed of your rotation, while Time.deltaTime makes sure your rotatespeed is independent of your framerate.
You can always use other axes to rotate around, depending on what you want.
Cheers ;)
Answer by whydoidoit · Jul 04, 2012 at 07:01 AM
Your problem is that transform.eulerAngles returns a struct which is a copy of the value - so you aren't updating anything.
var angles = plane.transform.eulerAngles;
angles.y -= 180;
plane.transform.eulerAngles = angles;
Your answer
Follow this Question
Related Questions
Wheel Collider Rotation Problem 0 Answers
rotating an object so the face nearest another objects face is parallel 2 Answers
Unity Car Tutorial Rotate Snippet Chaos 0 Answers
[C#]Angle of shooting equale to mouse direction 1 Answer
How to change an objects position and rotation inside a script? 0 Answers