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]

It looks like RotateAround() is buggy in the engine API. When I do this in the OnUpdate() of a camera:

if (mouseY_input_axis.Value != 0) {
	camera_angle_y += mouseY_input_axis.Value * view_speed_y;
	Actor.RotateAround(Actor.Position, Actor.LocalTransform.Right, camera_angle_y);
if (mouseX_input_axis.Value != 0) {
	camera_angle_x += mouseX_input_axis.Value * view_speed_x;
	Actor.RotateAround(Actor.Position, Vector3.Up, camera_angle_x);

it works for the X axis, but fails on the Y axis, I get a random-looking chaotic rotation. Am I doing something wrong? (the camera has no parent). I’m trying to achieve some kind of simplified FPS-style camera, with horizontal rotation in world space around global up axis going through the camera’s location, and vertical rotation in local space around camera’s local X axis.

Hmm I’m not sure. You could try LookAt maybe.