BoxCollider

The BoxCollider component defines a rectangular collision shape. It can be used for physics interactions and collision detection. See Physics for an overview.

Options

OptionTypeDefaultDescription
widthnumber0Width of the rectangle.
heightnumber0Height of the rectangle.
rotationnumber0Rotation in radians.
offsetVector2(0, 0)Offset from the entity’s position.
layerstring""The collision layer the collider belongs to.
physicsbooleantrueIf true, the collider interacts with rigid bodies.
ignoreCollisionsWithLayersstring[][]Layers this collider ignores.

Example

import { Transform, BoxCollider } from "angry-pixel";

this.entityManager.createEntity([
    new Transform(),
    new BoxCollider({ width: 16, height: 16, layer: "Player" }),
]);

Add a RigidBody to the same entity to make it move and respond to physics.