How to find current vertical axis
Hello, is there a way to find the current vertical axis of an object?
You can see the picture above. After rotation the Y axis is more like X and X is more like Y. But I still need a vertical rotation and in this case around X, but after many different rotation the axis change a lot and do not know which one is vertical - Y, X or Z. Can I always rotate around the current vertical axis?
Do you mean in the scene view or in code?
In the scene view you can toggle between "local" and "global" handles
I mean in code. I wan to write a script to rotate the cube by its current vertical axis that can be different from Y by rotations.
I mean in code. I wan to write a script to rotate the cube by its current vertical axis that can be different from Y by rotations.
If you just want the local vertical axis you can retrieve it with the following line:
Vector3 verticalAxis = transform.up;
This will give you the local up axis, which i guess, is what you want.
EDIT:
In case you want to rotate around the world y axis all the time you would have to do something like this: transform.RotateAround(Vector3.zero, Vector3.up, 20 * Time.deltaTime);
This should rotate around the world y axis which is unaffected by the local y axis of the gameobject. Dont forget to add the position of the box as first parameter. Here it is set to Vector3.zero which would set the position of your box to 0,0,0 as well. You can find this method here: https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html
Answer by evrov · Nov 11, 2016 at 01:04 PM
transform.up does not work correct in my case. By different rotations of the cube it loses the original place of the axis. For example the green axis (Y) may be changed to the place where was initially the X axis, as the picture above shows. In one moment I do not know where everyone axis is placed, but i want to rotate the cube from left to right as direction or the rotation must be Vector3.up, but in such a case it rotates again around the original Y axis and the cube rotates different. Is there a way to understand in every moment what is the orientation of every axis
On the picture the X axis now points up and then rotating to right or left must be around X axis.
Hey evrov, i updated my answer above with a codesnippet which lets you rotate aroudn the wodl y axis.
Your answer
Follow this Question
Related Questions
Axis are not rotated as I would expect. 0 Answers
How I can i rotate a bullet after spawning relative to the mouseposition? 0 Answers
How to rotate an object around a player when pushing a button..? 0 Answers
Make GameObject rotate around another around random axis but with fixed distance 0 Answers
constant rotation using keypress 0 Answers