How to use Euler angles to rotate an object ?

I have an object that I need to rotate from its local rotation by an amount of degrees,on all 3 axis? I have never used euler angles before, but I know that I should be using it as a normal rotation will not work…
Lets say I want to rotate my object with an angle of Vector3(264,29,319) and it’s current localRotation is (6,331,41) and the wanted final rotation of the object is (270,0,0).

Here are my suggested “rules” for how you deal with eularAngles in this situation:

  • Never read eulerAngles. Consider them write-only.
  • Keep your own Vector3 that represents the current rotation.
  • Never assign to an individual eulerAngles component (like eulerAngles.y). Always assign a Vector3 to eulerAngles.

Here is a simple script:

#pragma strict
 
public var speed = 1.0;
private var v3To = Vector3(2025,0,0);
public var v3Current = Vector3(0,0,0);
 
function Start() {
   transform.eulerAngles = v3Current; 
}
 
function Update () {
	v3Current = Vector3.Lerp(v3Current, v3To, Time.deltaTime * speed);
	transform.eulerAngles = v3Current; 
}

Note changes in rotation are made to v3Current and then v3Current is assigned to Transform.eulerAngles. This way v3Current will always reflect one euler angle representation of the ‘physical’ rotation. But note that the actual eulerAngles value will not necessarily match v3Current. But they will both represent the same ‘physical’ rotation.

Quaternion.Lerp() will select the shortest distance between two rotations, so that will not work for you. Vector3.Lerp() will literally interpret the values passed. So if you want to rotate the long way from 41 to 0, you have to change the values so the Lerp() walks that way. In this example, you would set the final rotation to 360 rather than 0.

Note in playing these games, you typically want to normalize the v3Current values back into a standard range (0 to 360 or perhaps -180 to 180) before calculating and setting the new destination angle.

Why not use Quaternian.Lerp to LERP the rotation to the target?

Try:
Quaternion.rotate(270,0,0);

See more: Euler

I’m just a noob to Unity (and 3d gaming/modelling) but I think there are fundamental issues with using Euler maths (in general - not just Unity) to rotate objects if you rotate more than one axis at a time - I believe you should be using Quaternian maths instead.

I used this logic in Unity 2021 and it worked fine.
I only needed to convert it to C#.

@robertbu
Thanks, very much.