How to get tranform rotation or eulerAngles without actually exectue a real rotation script.

How to get tranform rotation or eulerAngles without actually exectue a real rotation script. For example,

target.RotateAround( Vector3.one, Vector3.up, 16);

I want to know the rotation result of this above “target” without actually execute it… Is there any way to forcast the result?

1 Like

RotateAround will move the position and the rotation of your object. One simple way to do this is just save the old position and rotation, do the rotation, then restore the old position and rotation.

// Save the old data
Quaternion oldRotation = target.localRotation;
Vector3 oldPosition = target.localPosition;

// Try it out
target.RotateAround( Vector3.one, Vector3.up, 16);
Quaternion newRotation = target.localRotation;
Vector3 newPosition = target.localPosition;

// Restore old data:
target.localRotation = oldRotation;
target.localPosition = oldPosition;
1 Like

You can simply calculate it like this:

    public static void RotateAround(ref Vector3 position, ref Quaternion rotation, Vector3 point, Vector3 axis, float angle)
    {
        var q = Quaternion.AngleAxis(angle, axis);
        position = q * (position - point) + point;
        rotation = q * rotation;
    }

This method takes a position and a rotation (have to be variables) and then take the same arguments as transform.RotateAround. The method modifies the position and rotation you passed in just the same way as Transform.RotateAround. That’s all.

2 Likes