Get height of CharacterBody3D that is composed of multiple meshes dynamically

Godot Version



I have a CharacterBody3D where I am dynamically adding and removing meshes that are changing the total height of the body. Is there a way for me in GDScript to tell what the current max. height for the CharacterBody3D is? Like drawing a bounding box around it to get its current max. dimensions in all directions?

Reason why I am asking is because I want to display a rotation text above the CharacterBody3D and it should always be 5 units above the top of the CharacterBody3D

You can get and merge the AABBs of the meshes to get an overall bounding box.

Something like this:

func _bounding_box(node : Node) -> AABB:
	var ab : AABB = AABB()
	if node is VisualInstance3D:
		ab = node.get_aabb()
	for child in node.get_children():
		var cb = _bounding_box(child)
		ab = ab.merge(cb)
	return node.transform * ab