Get angle of rotation around local axis
Edit : Question was too long.
Ok so I have a world rotation, or say, a Transform. How can I get the rotation around its local X axis (transform.right) and local Y axis (transform.up)?
Thanks.
Implement a "Calibrate" Option which zeroes the current position by reading the gyro/accel and offsetting it in the calculations.
Where is "Calibrate" I cant find it, google doesn't help
I already have that. Still what I get is world rotation. for example my game is landscape. I'm laying down and turning to the side so my phone is portrait in world space. The rotation is then inversed this way (x becomes y and y becomes x). Using get orientation might do the trick but its only for per 90° angles. $$anonymous$$aybe if I can get the local Z rotation I can rotate the whole rotation so it seems like it's always in landscape world space.
btw using gameobject to simulate this is fine with me, it doesnt have to be pure scripting.
Detect the screen orientation and select the relevant code block accordingly.
Curiously there are two pages on screen orientation.
http://docs.unity3d.com/ScriptReference/ScreenOrientation.html
http://docs.unity3d.com/ScriptReference/Screen-orientation.html
I also did that. I've successfully nullified Z rotation but it seems like it wasnt really helpful.
I've done several tests, and got :
local Z rotation is the same as world Z rotation
Using the projection method, if I use the local forward axis as the perpendicular vector to get the local y rotation angle, it always return the same angle as world Y rotation.
If I use local Up as perpendicular vector, then the result will be unafftected by local Up rotation, but other axis rotations will. This goes for all axis combinations except local forward-up mentioned just before this.
Updated the question. Btw to simplify things I want to get the angle of the rotation around an object's local X and Y axis. localEulerangles won't do, it's relative to ita parent not its local axises
What do you mean by "I want to get the angle of the rotation around an object's local X and Y axis." local axis also rotates with gameobject. You can't get a relative rotation in its local axis. Did i get wrong ?
I thought since I can rotate around those axises they also have a time when the rotation around it is zero, and maybe I can get the amount of rotation that has been done around it. I've read a post on stackoverflow about how to get an angle around custom axis using projection, but it didnt work well for me.
Well if this is really impossible, or more like doesnt make sense, I'll just stop trying to make this work (cuz it wont)
Answer by bjennings76 · Dec 19, 2016 at 12:37 AM
It sounds like you are looking for the object's local Euler angles:
float localRotationX = transform.localRotation.eulerAngles.x;
float localRotationY = transform.localRotation.eulerAngles.y;
Your answer
Follow this Question
Related Questions
Using Local Angles to target enemy object 0 Answers
Rotation does not seem to make sense 2 Answers
Writing a simple script to rotate an object in direction of axis 0 Answers
How set rotation of a single axis 1 Answer
Rotating on other axis 1 Answer