The PolygonCollider component defines a convex polygon-shaped collision area for an entity.
It can be used for both physics interactions and collision detection.
The collider's shape is determined by a series of vertices that form a closed convex polygon.
Note that only convex polygons are supported - concave shapes must be broken into multiple convex polygons.
The shape can be offset and rotated, and collision layers allow controlling which objects can collide with each other.

const polygonCollider = new PolygonCollider({
vertexModel: [new Vector2(0, 16), new Vector2(16, 16), new Vector2(16, 0), new Vector2(0, 0)],
rotation: 0,
offset: new Vector2(),
layer: "CollisionLayer",
physics: true,
ignoreCollisionsWithLayer: ["IgnoredLayer"]
});

Implements

Constructors

Properties

ignoreCollisionsWithLayers: string[] = []

Ignores collisions with layers in the array

layer: string = ""

Collision layer

offset: Vector2 = ...

X-Y axis offset

physics: boolean = true

TRUE if this collider interact with rigid bodies

rotation: number = 0

Edges rotation in radians

vertexModel: Vector2[] = []

Collection of 2d vectors representing the vertices of the collider