I wanted to implement a feature similar to RotateAround in unity but it didn't work properly

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By WilliamShenzzz

Code

public static void RotateAround(this Node3D node, Vector3 point, Vector3 axis, float angle) {
    var centerInLocalSpace = node.ToLocal(point);
    var localPosition = node.GlobalTransform.Origin - centerInLocalSpace;
    var rotationQuat = new Quaternion(axis, angle);
    var rotationMatrix = new Basis(rotationQuat);

    localPosition = rotationMatrix * localPosition;
    var globalPosition = node.ToGlobal(localPosition + centerInLocalSpace);
    var rotation = rotationMatrix * node.GlobalTransform.Basis;

    node.GlobalTransform = new Transform3D(rotation, globalPosition);
}
:bust_in_silhouette: Reply From: spaceyjase

Existing answer: https://forum.godotengine.org/52262/is-there-any-equivalent-in-gdscript-the-rotatearound-method