- Home /
How to find what positional axis an object's green axis corresponds to?
I'm trying to find out what positional axis an object's green axis corresponds to with varying rotations.
For example, if Object A had a certain rotation, its green axis would correspond to its Z position. And if Object B had a different rotation, its green axis would correspond to its X position. What code will help me determine the green axis's positional axis?
If I understand your question correctly
red = x axis green = y axis blue = z axis
if you rotate on those in the inspector you will see rotation about these axis.
Answer by Kristinosis · May 15, 2017 at 05:24 PM
If I'm understanding your question, you're trying to detect which global axis your object's green axis is pointing to? So if your object had zero rotation and its green axis was pointing straight up, meaning it corresponds to the global y axis, but if it was rotated 90 degrees on the z axis then now the green axis would be pointing right, and corresponding to the world x axis. Is that right?
If that's what you're asking, you could do a simple check by comparing transform.up with Vector3.up, Vector3.right, and Vector3.forward. You could also compare angles if you want to get the closest global axis that the green axis points to. I could probably write out some code when I get home but you should try it out yourself first.
If that wasn't your question, do you think you could maybe reformulate it?
Thanks! Comparing the object's transform.whatever to Vector3.forward worked!
Answer by Bunny83 · May 15, 2017 at 06:13 AM
Your question is a bit confusing. The green axis inside the scene view when, the scene view is switched to "local", is always transform.up ( which is always the y-axis of that object in worldspace), no matter how the object is rotated.
If the sceneview mode is switched to "global", the green axis is always aligned with the world and therefore completely independent from the object rotation. Though transform.up is not affected by this setting.
In general the x axis is red, y is green and z is blue. To avoid confusion it's recommended to use the mode "local" and "pivot" instead of "global" or "center". If you use one of these you should understand that it's just a visual tool to simplify certain editing actions in the sceneview. Changing this setting in the Unity editor does not affect the object itself.