🔄Rotator

Stabilizes Euler rotations for smooth interpolation

Unity calculates rotation using quaternions which when converting to and from Euler angles may cause data loss resulting in inadvertent flipping or collapsing multiple rotations into a partial one.

Problem

Normally, a user sets an object's rotation in the Transform editor and all appears to be fine.

However, when this value is accessed via script as shown below, it returns a different value:

Debug.Log("Rotation:" + transform.localEulerAngles);

OUTPUT: 
Rotation:(357.8, 180.0, 180.0)

This is particularly problematic for scripts which read and modify rotation values during Update.

Solution

Rotator solves the problem by storing Euler values separately in a simple component so that it does not rely on getting Euler angles from the Transform. This allows rotations to have any value desired and maintains continuity in animations.

Use the Rotator editor to set Euler rotations without limits.

The Rotator component is applied automatically whenever animating an object's rotation.

World Space

When enabled, Euler angles are applied in world space rather than local space. This may be enabled automatically by behaviors that require world space rotation, such as Look At.

Use Physics

This option should be enabled for any object with a Rigidbody component to interact with physics. When enabled, rotation is applied using Rigidbody.MoveRotation.

Rotator has been built into the AxonGenesisBehavior base class for easier access and setup throughout scripts in Timeflow. Please see Rotator.cs for more info.

Context Menu

Additional commands can be found by clicking the 3 dotted menu on the right side of the inspector.

Flip X | Y | Z | All Axes

Applies a 180 degree rotation to the selected axis, or all axes. Use this to flip the orientation of the rotation.

Invert X | Y | Z | All Axes

Multiplies the axis rotation by -1 to reverse the direction of rotation.

Round Values

Applies rounding to each axis value, converting them to integer values.

Wrap 90 | 180 | 360

This constrains rotations to the selected amount of degrees. Instead of clamping values, this wraps the values within the range (negative to positive).

Last updated