Rotate but keep initial offset

I have a script that does what I need it to do, rotate the object with Mathf.sin. But I have created a bit of monster to get to where this is easily applied to my models.

I need my script to apply the rotation offset while keeping the rotational values already present on the object. I’m currently doing this…

transform.localRotation = Quaternion.Euler( new Vector3(Xphase * X_Angle, Yphase * Y_Angle, Zphase * Z_Angle));

I know this is not the right way to go about this, but I’ve tried world rotations as well, and that is not what I want either. Thanks in advance.

?

How about you describe the situation you have and what you expect for behaviour. This sentence makes little sense without greater detail. I am unsure how one rotates while keeping the present rotational values.

That’s like the game my dog likes to play, “throw, but don’t take… throw, but don’t take”

1 Like

I have an object that is currently rotated at X: 3, Y: -34.09, Z: 187.098
I have another object rotated, X: 0.098, Y: 64.098, Z: 54.23

These are the current rotational values.

I need my script to rotate these models without overwriting this original offset, but by

If I set the script to animate the first model with an offset value of 1 on the X, 0.5 on the Y, and 0.1 on the Z, it needs to be applied from the original rotation, not erasing the original rotation.

So the first model rotation on the X should go up to 4 on the X, and the second model should go up to 1.098 on the X.

Oh, you want to APPEND a rotation.

You can use the Transform.Rotate method:

Or even the Transform.RotateAround method, if you need to rotate around a point other than the origin:

Otherwise you can create a Quaternion and append it to the current rotation:

transform.localRotation *= Quaternion.Euler(Xphase * X_Angle, Yphase * Y_Angle, Zphase * Z_Angle);

note, change to ‘rotation’ if you’re rotating in global space. ‘localRotation’ rotates in local space.

Becuase really, that’s all ‘Rotate’ does, it wraps around the Quaternion calculation.

Awesome, that worked, thank you sir