Hello to all,
Here’s my setup: I have a cube which has 6 exterior faces which can be rotated individually along their Y (up) axis. Here are the cubes showcasing their pivot and local axis
The faces are rotated on Y axis with mouse drag with the following code:
Vector3 _mouseOffset = (Input.mousePosition - _mousePos);
Vector3 _rotation = Vector3.zero;
_rotation.y = (_mouseOffset.x + _mouseOffset.y) * rotationSpeedEditor;
_selectedFace.transform.Rotate(_rotation, Space.Self);
_mousePos = Input.mousePosition;
Now here’s the problem. Upon releasing the mouse, I want to smoothly rotate the face to the closest value between 0, 90, 180, 270 but assigning the localRotation I don’t get the desired effect because one face is rotating on the local Y axis and the other on the local X axis. Shouldn’t both of them be using the local Y for rotation?
Here’s the code I use upon releasing the mouse button
Vector3 currentRotation =_selectedFace.transform.localRotation.eulerAngles;
float currentRotationY = currentRotation.y;
if(currentRotationY <= 45)
{
currentRotation.y = 0;
}
else if (currentRotationY <= 135)
{
currentRotation.y = 90;
}else if (currentRotationY <= 225)
{
currentRotation.y = 180;
}else if (currentRotationY <= 315)
{
currentRotation.y = 270;
}
else
{
currentRotation.y = 0;
}
_selectedFace.transform.DOLocalRotate(currentRotation, .2f);
I know I am missing something here but cannot figure out what. Any help is highly appreciated.
EDIT:
Just for clarification, I am wondering why rotating the face on the local Y axis, Unity reports it as rotating on the X axis. Added image to showcase the issue:
Local Rotation With Log