Transform.RotateAround() how to implement it on Flax Engine

Hey! Someone can tell me how to implement (Unity)transform.RotateAround to Flax Engine(C#).

I would try sth like this:

using FlaxEngine;

public class TestRotateAround : Script
{
    public Actor Target;

    /// <inheritdoc/>
    public override void OnUpdate()
    {
        // Spin actor around the target at 40 degrees/second
        RotateAround(Target.Position, Vector3.Up, 40 * Time.DeltaTime);
    }

    public void RotateAround(Vector3 point, Vector3 axis, float angle)
    {
        Transform transform = Actor.Transform;
        Quaternion q = Quaternion.RotationAxis(axis, angle * Mathf.DegreesToRadians);
        Vector3 dif = transform.Translation - point;
        dif = dif * q;
        transform.Translation = point + dif;
        transform.Orientation = q;
        Actor.Transform = transform;
    }
}

Add script to object on a scene and plug in the Target field to object to rotate around it.

I guess it’s quite useful so maybe we will put it into engine API for ease of use.

1 Like

Please put it into engine API. :pleading_face:

Its Working but not smoothly in need smooth rotation.[Fixed]