S
S
Senture2019-01-12 19:34:03
Unity
Senture, 2019-01-12 19:34:03

How to get rotation angle value by y coordinate in gameobject?

Hello, I need to get the value of the gameobject's rotation angle, but I still can't do it, tell me in which direction to dig?
This is what I need to get:
5c3a15b4235dc800325074.png
This is what I get in the end:
5c3a15d71baa2039688841.png
The one circled in blue is what I get like this:

mainObject.GetComponent<Transform>().rotation.normalized.y

And what is circled in blue, I get like this:
mainObject.transform.rotation.ToAngleAxis(out y, out v) // в Y переменной типа float

And what I noticed:
Everything is displayed correctly up to a value of 360, and if the object is rotated, for example, by 361 degrees, then from the code I will get an answer of 359, or rather 358.9999
I don’t know what to do -_-
PS Many thanks to everyone

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2019-01-12
@Senture

I don't know why you need a transformation..
mainObject.transform.rotation.ToAngleAxis(out y, out v);
would you describe what effect you want to achieve ... what and how to rotate))
repeat the angle along Y.
did you try it ??
but I think it will be the same ..
you see, the point is in what ..
Quaternion.Lerp - it will always turn in the NEAREST side))
quaternions are generally arranged like this))
it will not work for you to do "two turns clockwise" or something similar .. like this way ..
for rotation, this is equivalent to the fact that nothing has changed ..
you can try to remember and accumulate exactly NUMBER .. ANGLE))
and then lerpit, for example, from zero to 720 ...
just substituting Y directly.
then there will be two turns clockwise ..as in animation..
good luck.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question