Create collisions for AABB bounding box

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

Is there a way of creating collisions for an AABB? I expect 6 box shapes would need to be created, sized and aligned for each of the 6 sides of the AABB, but I’m not sure exactly where to start with this?

:bust_in_silhouette: Reply From: Inces

AABB is a simple 3d box shape. So You can use just one box shape collision. AABB.size is an actual scaling of this box. Other properties define position, and You don’t need all of them, just use origin to set up start of a collision box.

Ahh, I should have mentioned I need the collisions to be on the outside, since the AABB is actually the bounds of the gridmap, I want to automatically generate collision around the edge so nothing can leave it. I’m making a start:

var boundsbox_node = $BoundsBox
boundsbox_node.get_node("Left").shape.extents = Vector3()
boundsbox_node.get_node("Right").shape.extents = Vector3()

So I need to set each of the collision shapes (Left, Right, Top, Bottom, Front, Back) to match each side of the AABB?

elvisish | 2022-08-16 20:42

Can’t You use one collision box and code stopping elements on when they try to exit it instead ? :slight_smile:

Inces | 2022-08-16 20:48

I want to be able to move_and_slide() against the edges, and I don’t believe that would be easily possible this way?

elvisish | 2022-08-16 20:49

Ok, lets try something first. Use collision box with AABB scaling just like I said, but make all of the extents minus sign. I wonder if it would invert the box, so collision will happen from inside to outside, and move_and_collide will work with that

Inces | 2022-08-17 12:23

How do I set the BoxShape to the size of the AABB? BoxShape has extents but AABB has nothing similar, should I take the size and position and halve it?

elvisish | 2022-08-17 21:32

just the size, and halve it propably, then multiply by -1

Inces | 2022-08-18 14:15