Skip to content

Polygon Collider 2D

A collision shape with any outline you like.

The vertices outline the shape in order, relative to the entity's position. Concave shapes are fine, because the outline is split into triangles. The default is a pentagon.

Scene file

Saved as a <PolygonCollider2D> element inside the entity's <Entity> element. Attributes that are left out keep their default. See Scene Files for how values like vectors, colours and file paths are written.

<PolygonCollider2D IsTrigger="false" Layer="1" Mask="65535">
    <Offset X="0" Y="0"/>
    <Vertex X="0" Y="1"/>
    <Vertex X="-1" Y="-1"/>
    <Vertex X="1" Y="-1"/>
</PolygonCollider2D>
Name Where Type Default
Vertex child X Y, repeatable float, one per corner, in order a pentagon
Offset child X Y float, shape offset from the entity's position 0, 0
IsTrigger attribute bool, reports overlaps without blocking false
Layer attribute int, bit of the collision layer the collider is on 1 (Default)
Mask attribute int, bits of the collision layers it collides with 65535 (everything)
PhysicsMaterial child Filepath, optional path to a .physicsmaterial (density, friction, restitution) built-in defaults

Collider sizes are multiplied by the entity's transform scale. Without a Rigid Body 2D on the same entity, the collider is attached to a body that doesn't respond to forces or gravity, so it acts as a solid obstacle. A Lua Script on the entity can define OnBeginContact(other, normal, point) and OnEndContact(other) to hear about collisions and trigger overlaps.

The shape is built when the game starts, so changing collider properties while it's running has no effect.

Lua scripting

Properties

  • Layer (string): Name of the collision layer this collider is on (read-only)
  • Mask (table of string): Names of the collision layers this collider collides with (read-only)
  • Offset (Vec2): Offset of the shape from the entity's position
  • PhysicsMaterial (PhysicsMaterial): Density, friction and restitution of the shape, or nil for the defaults
  • Vertices (table of Vec2): The polygon's corners, relative to the entity's position

Functions

  • CollidesWithLayer(): Whether this collider's mask includes the named collision layer