Skip to content

Polygon Collider

The PolygonCollider defines a convex polygon shape with up to 8 vertices. It is useful for custom collision shapes that cannot be represented by boxes, circles, or capsules.

Properties

PropertyTypeDefaultDescription
verticesVec2[]Unit squarePolygon vertices in physics units (local space). Max 8 vertices. Default: [{x:-0.5,y:-0.5}, {x:0.5,y:-0.5}, {x:0.5,y:0.5}, {x:-0.5,y:0.5}]
radiusnumber0.0Skin radius applied around the polygon. Creates a rounded polygon when > 0
densitynumber1.0Mass density
frictionnumber0.3Surface friction
restitutionnumber0.0Bounciness
isSensorbooleanfalseTrigger zone without physical response
enabledbooleantrueEnable/disable the collider
categoryBitsnumber1Collision filter category bits
maskBitsnumber0xFFFFCollision filter mask bits

Vertex Editing in Scene View

When an entity with a PolygonCollider is selected in the editor, vertex handles appear in the Scene View:

  • Drag a handle to move a vertex
  • Double-click on an edge to add a new vertex (if under the 8-vertex limit)
  • Right-click a handle to remove a vertex

Usage

commands.spawn()
.insert(Transform)
.insert(RigidBody, { bodyType: 2 })
.insert(PolygonCollider, {
vertices: [
{ x: -0.5, y: -0.5 },
{ x: 0.5, y: -0.5 },
{ x: 0.3, y: 0.5 },
{ x: -0.3, y: 0.5 },
],
});

Tips

  • Keep polygons simple. Fewer vertices means better performance.
  • The radius property adds a skin around the polygon, which can reduce collision jitter for stacking scenarios.
  • For concave shapes, split them into multiple convex PolygonCollider entities and parent them under a single root entity.

See Also