- Home /
Code to rotate around a local axis until local Y is 0?
This sounds pretty simple but it's proving to be pretty complicated unless I'm missing something super obvious. I have an object with a random rotation, let's say (-30, 15, 20). What I want to do is rotate this around its local Y until the Y rotation value (seen in the inspector) is 0. When this is satisfied, the object's Z axis will be pointing along the global YZ plane. At first, it seems like if you rotate locally by -15 degrees would work, but since the Y rotation is also being influenced by the X and Z, this doesn't work.
This can easily be done by dragging the rotation gizmo until the Y value is 0. When I do this, the Euler values come out to be (-24.156, 0, 26.887). It's proving pretty tricky to calculate that angle that the object is actually rotating in order for its Y to be 0. It's also proving difficult to calculate the vector that the object's Z vector should be pointing to, otherwise I'd use LookRotation or FromToRotation, or just calculate that angle using the dot product. I've been stuck on this stupid issue for weeks, can't wait to finally solve it so I can move on with working on my project. Thanks!
Your answer
Follow this Question
Related Questions
Why is my object's local x rotation not going past 90 degrees? 1 Answer
Complicated Rotation Issue 1 Answer
how to apply overall rotation to collection of rotated objects 0 Answers
Copy local rotation on one axis of A to B 1 Answer
How to get Angle float of specific axis.(Turret clamping related). 2 Answers