- Home /
How to get Objects, Rotation?
Hi everyone! I'm trying to track objects Z rotation, through ChassieRotation = transform.eulerAngles.z;
, but it's got several problems:
1st problem: When I start project, transform.eulerAngles.z;
returns strange value -7.017183e-15
. That's makes me sad.
2nd problem: transform.eulerAngles.z;
returns different value, as object's Z rotation. I need to catch rotation on - 90
.
How can I get actual object's Z rotation value?
And What is this mysterious value -7.017183e-15
?
( video : https://www.youtube.com/watch?v=5BwXYViKBIA )
Resolved it by using triggers, but anyway interested in answering of questions above.
Answer by malkere · Jan 25, 2017 at 09:04 AM
the pictures you posted are showing correct outputs. -7.017183e-15 is basically 0.00000000000007. while -90 is also basically 270 because -90 plus 360 is 270. the e-15 means the decimal place has been moved 15 spaces.
Well if you were trying to get zero and 270(-90) in those cases you just need to adjust the number. using an if (rotation < 0) { rotation += 360 } else if (rotation > 0) { rotation -= 360 } will make sure you always get 270 not -90. and if you $$anonymous$$athf.RoundToInt(rotation) you can get 0 ins$$anonymous$$d of 0.7e-15. Is that what you wanted?
I guess yess, so it's inpossible to get default values? Not modified?
I'm not sure what you mean by "default values," 0-360? What is rotating the landing gear? Unity doesn't automatically jump from 0 to 359 when going backwards, but you can certainly do it yourself if you want to measure things strictly. I often add a if (value < 0) { value = 0; } after I subtract something to make sure it doesn't go negative. Unity will just do what it tells you so you just have to figure out smarter ways of controlling your commands.
I need to catch this value: http://joxi.ru/$$anonymous$$AjGQy8i4dgRVr
Is it possible?
I did some research and it looks like it is not possible. There really should be no reason for you to need that number though. If you control the code properly it will always be exactly the number you want it to be regardless of what the inspector says. There was an in depth discussion about it here: https://forum.unity3d.com/threads/how-to-get-euler-rotation-angles-exactly-as-displayed-in-the-transform-inspector-solved.425244/
Your answer
