AABB of a CharacterBody3D or a CollisionShape3D?

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

Is there a way to get the AABB of a CharacterBody3D or a CollisionShape3D? I want to know the overall bounding box of my character without worrying about the exact shape being used so I can avoid spawning some things inside of the player’s space.

:bust_in_silhouette: Reply From: zhyrin

While I didn’t find a ready solution for this, I was thinking that in the editor you clearly see the AABB update live, so there must be something built-in that does this. My research has lead me to these files

  • scene/3d/node_3d.h - here you’ll find a Node3DGizmo defined
  • scene/3d/node_3d.cpp:212 - here you see all the gizmos’ transform() method called (only in editor)
  • editor/plugins/node_3d_editor_gizmos.h/.cpp - the actual implementation(s) of Node3DGizmo

I haven’t found if this contains any code you could use, but I haven’t looked that hard either. The last .cpp file does reference AABB often though.
By looking at this you might be able to figure out how the editor draws the AABB for 3D nodes, and then you can implement it yourself.

Oh wow, thanks for digging! I didn’t even consider seeing if the editor can do this.

I poked around for a little while, though, and while I’m not 100% sure how the editor is generating the bounding box, I think it might be limited to only showing bounding boxes around things that have meshes?

As you can see in this screenshot, when I have the root Player node selected, the orange bounding box appears to be cutting right through the collision capsule but it includes the cube mesh that I moved off to the side, so I think the shape is just not part of whatever process generates this, unfortunately. (I wonder if that’s a bug of sorts?)

bigzaphod | 2023-03-12 16:48