Rotation direction in coroutine

I have a weird problem concerning rotating objects. The object in question is shaped like a plate and positioned horizontally. Now I want to flip it over and turn it into vertical position at the same time. Basically, I want its rotation to go from Euler(90,0,0) to Euler(270,90,0). My problem is, I want it to go there in the obvious direction, increasing both angles, but it rotates the other way.
I don’t want to use animations, this is not the only rotation I’ll have long term and a coroutine just seems better suited.

I’ve tried quaternion.slerp, quaternion.lerp, vector3.lerp in combination with Euler and eulerAngles as well as splitting the rotation into two parts from start to the midway rotation and from there to the target. It keeps rotating in the wrong direction. I’ve also tried using (-90,90,0) as the target, also when I try to change the angles at runtime in the inspector, it keeps converting them to something strange… Debug.log tells me the Euler angles are right, but it either converts them wrong when going to a quaternion or does something I have no idea of. I’m really clueless, what am I doing wrong?

There are two issues here. The first is that Quaternion.Slerp() takes the shortest distance between the two rotation, so it will not go around the long way. The second issue is there are multiple euler angle representations for any “physical” rotation, so you cannot depend on Unity using any specific one. As you found out, you can set an angle to something like (180,0,0), and immediate read it back and get (0,180,180) (which is the same physical rotation).

One solutions is to manage the angle yourself. That is to create and use your own Vector3 and treat Transform.eulerAngles as “write-only.” Never read eulerAngles and expect any particular representation. Since you never cross the 0/360 boundary for your target angles above, you can do something like:

var v3Rot = Vector3(90,0,0);
var v3Dest = Vector3(270,90,0);

var speed = 4.0;
 
function Start () {
	transform.eulerAngles = v3Rot;
}

function Update() {

	v3Rot = Vector3.MoveTowards(v3Rot, v3Dest, speed * Time.deltaTime);
	Debug.Log(v3Rot);
	transform.eulerAngles = v3Rot;
}

I’m not sure if I’m answering your question or not but if you are having problems with the rotation taking the long way instead of the short way you might check out this question on SO about determining rotation direction