A
A
Alexander Fandeev2021-02-12 09:37:09
C++ / C#
Alexander Fandeev, 2021-02-12 09:37:09

How does Y axis rotation work in Unity?

Only recently I started to study the Unity engine based on Hawking's book and immediately ran into a number of problems. First of all, the process of the player's rotation along the Y axis is not clear, and why the X axis with changed parameters is involved here. And also what exactly does the localEulerAngles method of the transform class do. Below is the code:

else if (axes == RotationAxes.MouseY) {
_rotationX -= Input.GetAxis(“Mouse Y”) * sensitivityVert;

_rotationX = Mathf.Clamp(_rotationX, minimumVert, maximumVert);

float rotationY = transform.localEulerAngles.y;

transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);


If there is such an opportunity, could you explain exactly what logic this code works for, because I can’t understand in any way.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Mamchenko, 2021-02-12
@alexandrfandeev

I can hardly explain the logic of the code, because I am also learning now
. If you have a 2D game, then instead of rotating the object along the Y axis, you will see its size change, because it is a 2D object and it is flat, and if you have a 3D game, then you will see how the 3D object rotates. In general, rotation along the Y axis is just rotation around this axis ...
Again, if the game is 2D, then when rotating along the Y axis, the object will visually change size, and along the X axis, it (the object) will rotate, and if the game is in 3D, then the author of the book will rotate the object as he needs it, that is, it is unlikely that anyone will be able to answer the question "why exactly along this axis", because we do not know the purpose of this all.
localEulerAngles is a rotation along the local axis, that is, the project has a global coordinate axis (normal and familiar X, Y, Z), but at the same time, each object has its own axis - the local axis, I advise you to search the Internet for information about these axes, and EulerAngles means that we will rotate the object through Euler angles - the most familiar rotation angles to us (in the case of geometry - not only rotations), many of them have studied geometry, but there is Quartenion - these are quartenion angles, they are a little more complicated, in addition to the X, Y and Z, some unknown value w is added there, I have not studied this, because Euler angles are easier and more familiar to me.
If I did not answer correctly or even could not answer your questions, then forgive me ... ._.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question