BoundingBox
Axis-aligned bounding box (AABB) for entity collision detection.
Access
Section titled “Access”BoundingBox boundingBoxComponent = store.getComponent(ref, BoundingBox.getComponentType());Box box = boundingBoxComponent.getBoundingBox();Box Dimensions
Section titled “Box Dimensions”Box box = boundingBoxComponent.getBoundingBox();
// dimensionsdouble width = box.width(); // max.x - min.xdouble height = box.height(); // max.y - min.ydouble depth = box.depth(); // max.z - min.zdouble volume = box.getVolume();
// cornersVector3d min = box.getMin(); // minimum cornerVector3d max = box.getMax(); // maximum cornerCreating Bounding Boxes
Section titled “Creating Bounding Boxes”// horizontally centered at origin, bottom at y=0 (typical for entities)Box entityBox = Box.horizontallyCentered(0.6, 1.8, 0.6);// creates: min=(-0.3, 0, -0.3), max=(0.3, 1.8, 0.3)
// explicit min/max cornersBox customBox = new Box(-0.5, 0.0, -0.5, 0.5, 2.0, 0.5);
// set on entitystore.putComponent(ref, BoundingBox.getComponentType(), new BoundingBox(entityBox));Detail Boxes
Section titled “Detail Boxes”For complex collision shapes, entities can have named sub-hitboxes:
Map<String, DetailBox[]> detailBoxes = boundingBoxComponent.getDetailBoxes();
// detail boxes are typically set from ModelComponentboundingBoxComponent.setDetailBoxes(model.getDetailBoxes());Detail boxes are used for precise hit detection (e.g., headshots) rather than general collision.
Automatic Updates
Section titled “Automatic Updates”When an entity has a ModelComponent, its bounding box is automatically updated:
ModelSystems.ModelSpawned- sets initial bounding box from modelModelSystems.UpdateBoundingBox- updates when model changesUpdateCrouchingBoundingBox- adjusts for crouch state
Collision System
Section titled “Collision System”Entities with BoundingBox + TransformComponent (and without Intangible) are tracked in spatial queries for collision detection.
Finding Collisions
Section titled “Finding Collisions”CollisionResult result = new CollisionResult();
// find what a moving box would hit (static method)boolean hit = CollisionModule.findCollisions( boundingBox, // the collider shape position, // starting position velocity, // movement direction result, // stores collision data componentAccessor);
if (hit) { BlockCollisionData collision = result.getFirstBlockCollision(); if (collision != null) { Vector3d hitPoint = collision.collisionPoint; Vector3d normal = collision.collisionNormal; }}Entity-to-Entity Collision
Section titled “Entity-to-Entity Collision”// check if two entities overlapBoundingBox boxA = store.getComponent(refA, BoundingBox.getComponentType());BoundingBox boxB = store.getComponent(refB, BoundingBox.getComponentType());TransformComponent transformA = store.getComponent(refA, TransformComponent.getComponentType());TransformComponent transformB = store.getComponent(refB, TransformComponent.getComponentType());
// manual AABB intersection checkBox worldBoxA = boxA.getBoundingBox().clone().translate(transformA.getPosition());Box worldBoxB = boxB.getBoundingBox().clone().translate(transformB.getPosition());boolean overlaps = worldBoxA.isIntersecting(worldBoxB);Excluding from Collision
Section titled “Excluding from Collision”Add the Intangible component to exclude an entity from collision queries:
store.ensureComponent(ref, Intangible.getComponentType());See Intangible for details.
Related Components
Section titled “Related Components”| Component | Relationship |
|---|---|
TransformComponent | Provides position for world-space collision |
ModelComponent | Source of bounding box dimensions |
Intangible | Excludes from collision spatial queries |
Invulnerable | Separate from collision (affects damage only) |