how can I rotate an entity around a center?

Hi,
I am wondering how can I rotate an entity around a center.

For example, I use a box as a sword, and I would like to generate a sword entity (I finished this part), and make it rotate at a specific angle in a specific direction. I am not sure how can I solve the problem.

Besides, I was wondering if an entity can move to follow a specific track?

You can try these. The second one (RotateAroundPoint) hasn’t been tested but I think that’ll work

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static void SetRotationAroundPoint(ref quaternion rotation, ref float3 translation, float3 aroundPoint, quaternion targetRotation)
        {
            float3 localPointToTranslation = math.mul(math.inverse(rotation), translation - aroundPoint);
            translation = aroundPoint + math.mul(targetRotation, localPointToTranslation);
            rotation = targetRotation;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static void RotateAroundPoint(ref quaternion rotation, ref float3 translation, float3 aroundPoint, quaternion addedRotation)
        {
            float3 localPointToTranslation = math.mul(math.inverse(rotation), translation - aroundPoint);
            rotation = math.mul(addedRotation, rotation);
            translation = aroundPoint + math.mul(rotation, localPointToTranslation);
        }

You can convert euler angles to quaternions using “quaternion.Euler”

1 Like