Replacing get_transformed_aabb() upgrading my Godot 3.5.1 project to Godot 4

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

Can anyone help me replacing get_transformed_aabb() upgrading my Godot 3.5.1 project to Godot 4?

I have a RigidBody3D with a MeshInstance3D subnode, the body is translated and rotated, and in previous version i’ve mesh_inst.get_transformed_aabb() to get its transformed bounding box.

If i get mesh_aabb = mesh_inst.get_aabb(), then how can i transform this to obtain the same old get_transformed_aabb() value?
Can i use mesh_inst.to_global() someway?

Thanks & hugs! Mikel

Edited to format the code. Use `` for inline code, as _ in names will get replaced as italic text

Zylann | 2023-07-07 11:50

:bust_in_silhouette: Reply From: Zylann

The documentation doesn’t seem to indicate that get_aabb() gives you a local space AABB, basically from the mesh: https://github.com/godotengine/godot/blob/443820686cad24bbdd7e7050fa3d3f33f43a7bb5/scene/3d/mesh_instance_3d.cpp#L219

So maybe you can do mesh_instance.global_transform * mesh_instance.get_aabb()? Transform3D — Godot Engine (stable) documentation in English

Yes all right transforming directly by AABB!! thank you Zylann :wink:

tximikel | 2023-07-07 12:27

Bear in mind that transforming the aabb may give a bad result depending on what you are going for because it will no longer be “axis aligned”. Imagine a sphere surrounded by it’s aabb, rotate the whole thing 45 degrees and the box’s corners will be sticking out taller and wider.

The box always has to be sticking out somewhere of course but for most cases you want it to be aligned with the global xyz axes.