- Home /
The question is answered, right answer was accepted
How do I rotate around z-axis as if I am rotating around x-axis?
Let's say I have a cuboid here. When I rotate it around x-axis for 90 degrees, it stands up.
I want that when I input 90 degrees in the z-axis field, it will make the cuboid stand up too, instead of lying down like this.
I've tried to create an empty GameObject and make it the parent of the cuboid, then rotate the GameObject's x-axis and y-axis by 90 degrees. This made the cuboid stands up when I am rotating the cuboid's z-axis by 90 degrees, but it doesn't work for other degrees like 45 degrees. I want the cuboid to rotate around z-axis as if I am rotating around x-axis for all angles. Thanks in advance.
Answer by AudreyKwok · Aug 11, 2021 at 01:53 PM
This is the code I used:
var rotationCuboid = GameObject.Find("Cuboid").transform.localRotation.eulerAngles;
var rotationEmpty = GameObject.Find("Empty").transform.localRotation.eulerAngles;
GameObject.Find("Empty").transform.localRotation = Quaternion.Euler(rotationCuboid.z, 0, -rotationCuboid.z);
And it worked for me :D!
Answer by AudreyKwok · Aug 11, 2021 at 12:22 PM
One solution I came up with is to 1. Get the rotation angle of the cuboid 2. Rotate the empty parent’s x-axis by this angle 3. Rotate the empty parent’s z-axis by -1 * this angle Would this work? Is so, how do I implement this? Is there any better way than this?
Follow this Question
Related Questions
What are X, Y and Z referring to in Rigidbody and Configurable Joint? 0 Answers
Keeping Character Upright with Addtorque 1 Answer
Need to convert to/from right-handed coordinates 2 Answers
I want to calculate the coordinate points of both object and make fall body in pit. 1 Answer
Raycast using Transform.Up issue - FBX Model from Messiah 1 Answer