PolygonCollider

The PolygonCollider component defines a convex polygon collision shape from a list of vertices. It can be used for physics interactions and collision detection. See Physics for an overview.

Only convex polygons are supported. Concave shapes must be split into multiple convex polygons.

Options

OptionTypeDefaultDescription
vertexModelVector2[][]The vertices that form the polygon.
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, PolygonCollider, Vector2 } from "angry-pixel";

this.entityManager.createEntity([
    new Transform(),
    new PolygonCollider({
        vertexModel: [new Vector2(0, 16), new Vector2(16, 16), new Vector2(16, 0), new Vector2(0, 0)],
        layer: "Ground",
    }),
]);

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