# Using Euler angles to rotate object 360 degrees

I'm trying to create script that rotates object in given axis by set amount of degrees.

That's my 2 core methods

public Vector3 rotation;

public void RotateDegreesFast ()
{
transform.DOLocalRotate (GetTargetRotation (), rotationTime);
}

private Vector3 GetTargetRotation ()
{
Vector3 newRotation = new Vector3 (
rotation.x + transform.localEulerAngles.x,
rotation.y + transform.localEulerAngles.y,
rotation.z + transform.localEulerAngles.z)

return newRotation;
}


I was using this script for a little while, it was working perfectly in Y and Z axis. Now I try to rotate object 45 degrees in X axis (rotation = new Vector3(45f, 0f, 0f)). It works until rotation in x value equals 135. Transform.localEulerAngles.x is returning 45 instead of 135. So it's stuck between 90 and 135 degrees. I was trying to use transform.localRotation.eulerAngles.x instead, but it doesn't work as well.

I am aware this works that way because specific Euler angle can be represented in many ways. I also know that DOTween has DOLocalRotateQuaternion method, but the thing is that this component is often reused by a designer that sets value of rotation variable in the inspector. It's way easier to use Euler angles for him.

• Have you considered simply converting the designer's Euler angles to a quaternion, before passing them to DOTween's quaternion method? Also, please note that you can edit an existing question, instead of deleting it and re-positng? Commented Sep 8, 2020 at 15:01
• Thanks, somehow I didn't think about it. Commented Sep 8, 2020 at 15:37

public Vector3 rotation;