Change localRotation on keydown, only works once?
Hi all, quick very basic question. My code is to rotate the gameobjects local x rotation by 5deg every getkeydown. This works once but then will not work again. I don't understand as the localRotation should be 0,0,0 each time the Update() is run, as this object is the parent object. In my mind this should increase the rotation of the objects x axis by 5 deg each getkeydown event. Can someone please show me where I am going wrong, or even a simpler way to do this, thanks.
void Update()
{
if (Input.GetKeyDown("joystick button 4") && ObjectToRotate != null)
{
RotationAmount = 5;
ObjectToRotate.transform.localRotation = Quaternion.Euler(RotationAmount, 0, 0);
}
}
Answer by KelDG · Mar 24, 2016 at 03:09 PM
I managed to sort this, I didn't realise transform.Rotate used local orientation so I used that. Working well now.
if (Input.GetKeyDown("joystick button 4") && ObjectToRotate != null)
{
RotationAmount = -5;
ObjectToRotate.transform.Rotate(new Vector3(RotationAmount, 0, 0));
}
Your answer
Follow this Question
Related Questions
Changing parent at runtime rotates object. 0 Answers
Quaternion/World Local rotation problem 0 Answers
Using Local Angles to target enemy object 0 Answers
Questions about Rotations in unity 1 Answer