How to test for collisions when rotating a KinematicBody around a point?

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

I know I can rotate any spatial around a point using:

public static void RotateAround(Spatial obj, Vector3 point, Vector3 axis, float angle)
{
    obj.GlobalTranslate(-point);
    obj.Transform = obj.Transform.Rotated(axis, -angle);
    obj.GlobalTranslate(point);
}

But how can I rotate a KinematicBody around a point and still collide? Right now, it just phases through everything. The move_and_collide, move_and_slide, move_and_slide_with_snap, and test_move all only take translate vectors as params, but no rotational vectors.
One of my use cases:

When rotating this shape, the pivot point is at the bottom right of that blue cube, but when it collides with the ground, I want the pivot point to move to be where it collided. Is there any way to do that?

Is there even an easier way to do this?

:bust_in_silhouette: Reply From: DaddyMonster

Collisions come from the Godot’s physic’s engine and kinematic bodies access that with move_and_slide() (or move_and_collide) that will automatically return a collision which you can pick up in _physics_process with get_slide_collision so you need something along these lines:

func _physics_process(delta):
    if get_slide_count:
        var col = get_slide_collision[0]
        printt("You have hit:", col.collider)
    velocity = -global_transform.basis.z.rotated(Vector3.FORWARD, rotation) * rot_speed
    velocity = move_and_slide(velocity)

So I just take the negative z direction of the basis and rotate it along an axis and scale it up. Obviously you need to create the appropriate member variables.