Physics bodies get_aabb()

Godot Version

4.5.1

Question

Hey everyone, I have a question about using get_aabb() with physics bodies.

I have two bodies, and I want one to move on top of the other. This works fine as long as there’s no rotation, but once rotation is involved, it breaks. The body is a RigidBody set to frozen, but get_aabb() doesn’t seem to behave correctly with rotation.

I tried using a StaticBody instead, and that works well. However, I want the object to become a RigidBody when interacted with.

So my questions are:

Does RigidBody not work well with get_aabb() (especially with rotation)?

Am I using RigidBody incorrectly?

If I switch between StaticBody and RigidBody, will reparenting like that hurt performance?

VisualInstance3D.get_aabb() is local to the instance. You’ll need to transform it with its Node3D.global_transform to be able to get the transformed AABB.

Example:

extends Node


@onready var csg_box_3d: CSGBox3D = $CSGBox3D
@onready var mesh_instance_3d: MeshInstance3D = $RigidBody3D/MeshInstance3D


func _physics_process(delta: float) -> void:
	var aabb_t = mesh_instance_3d.global_transform * mesh_instance_3d.get_aabb()
	csg_box_3d.size = aabb_t.size
	csg_box_3d.position = aabb_t.position + aabb_t.size / 2.0

Result:

2 Likes