-EDIT-
My project is 3D and the camera perspective is similar to sports games like NBA 2K or soccer games in general. The input is a Vector2 obtained with the new input system. I need to move my player around with root motion, which means that my goal with this system is to calculate the rotation data to be passed as an animation parameter (using a event), so the correct animation is played and the player finally rotate according to the animation. The main part of the code (calculation part) was built by a friend of mine, who has more knowledge than me. This is my current code:
if (movementVector != Vector2.zero)
{
targetRotationAngle = Mathf.Atan2(movementVector.x, movementVector.y) * Mathf.Rad2Deg + cameraTransform.eulerAngles.y; //FUNCTIONAL CODE BUILT BY A FRIEND
targetRotationAngle = Mathf.CeilToInt(targetRotationAngle / 5) * 5; //FUNCTIONAL CODE BUILT BY A FRIEND
if (targetRotationAngle < 0)
targetRotationAngle += 360;
if (currentRotationAngle == targetRotationAngle)
return;
else
{
if (currentRotationAngle < targetRotationAngle)
{
Debug.Log("Clockwise rotation in " + (targetRotationAngle - currentRotationAngle) + " degrees");
}
if (currentRotationAngle > targetRotationAngle)
{
Debug.Log("Counterclockwise rotation in " + ((360-currentRotationAngle)+targetRotationAngle) + " degrees");
}
}
currentRotationAngle = targetRotationAngle;
}
This is a summarized version of my previous attempts (the ELSE part), I know my formula is wrong, cause it doesn't cover all the rotation scenarios, the more I tried to build, more of this IF's were nesting. That's why I've decided to ask...