Mixing transform.rotation and transform.rotate?
I am trying to make a game object rotate on the world z-axis when the player presses and holds a key, if the game object's rotation gets lower than 165 I want the rotation to be set back to 90, 0, 180. When it does reset though, instead of manipulating the z-axis it manipulates the y axis. What is happening here?
resetRotLeft = rotateObjectLeft.transform.rotation; // in start method public void rotateCannonLeft() { if (rotateObjectLeft.transform.eulerAngles.z < 345 && rotateObjectLeft.transform.eulerAngles.z != 0) { rotateObjectLeft.transform.rotation = resetRotLeft; } else { //rotate cannon z axis global Vector3 rot = new Vector3(0f, 0f, 1f * -speed * Time.deltaTime); rotateObjectLeft.transform.Rotate(rot, Space.World); } }
Answer by Xrank · Dec 11, 2020 at 07:35 PM
I found something that worked, it doesn't use both rotation and rotate but it still worked for me: https://forum.unity.com/threads/rotating-on-x-axis-causing-y-and-z-to-change-and-swap.381441/
Your answer
Follow this Question
Related Questions
Make GameObject rotate around another around random axis but with fixed distance 0 Answers
rotate an object with HTC Vive controller 0 Answers
My rotation is not the same in inspector as it is in the scirpt 0 Answers
ROTATION STOPS when i move the char on the air! 0 Answers
Get object's rotation around axis defined by vector 2 Answers