Skip to content

PolygonCollider

A shape for collisions with straight sides between its Points: a ramp, a wedge, a rock, a hill, a boat’s hull, a cup. Select it in the Scene view to drag its points, drag a plus on a side to add one, double-click one to take it off (Ctrl snaps to half units); Entity > Fit Polygon Collider to Sprite traces its sprite’s outline. A concave shape (an L, a cup) is split into convex pieces by itself. Points that don’t make a proper shape (fewer than three, all in a line, sides crossing) are fixed up and said so above its fields. Like a box, it stays upright whatever the entity’s rotation unless its BodyBody.Rotates: then it turns with the entity, round its middle, and tips, rolls over and stacks as it should.

Works with: Body (to make it move and fall)

Needed by: Body, Bouncer, Breakable, Bumper, Checkpoint, Crumble, DamageOnTouch, Dialogue, Door, Drain, FightingCharacter, FirstPersonMovement, GridMovement, Ladder, Lane, Patrol, Pickup, PlatformerMovement, Plunger, Pushable, Switch, Target, TopDownMovement, WireButton, WireSensor

Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.

  • points: text = “-0.5 -0.5; 0.5 -0.5; 0 0.5”. Its corners in order round it, as “x y” pairs separated by semicolons, in world units before the transform’s scale, round the entity (plus Offset): “-1 0; 1 0; 0 1” is a triangle 2 wide and 1 tall. They can go round either way. (Points: “x y” pairs separated by semicolons, e.g. “4 0; 4 3”; at least 3. The Inspector lists them a row each to set, add, remove and reorder.) (Field: its own editor: Points.)
  • offset: [x, y] = [0,0]. How far the shape’s center is from the entity, before the transform’s scale. (Field: a vector.)
  • isTrigger: true or false = false. Triggers don’t block movement; they report OnTriggerEnter/Exit instead. (Field: on or off.)
  • layer: text = null. A name for what kind of thing this is, e.g. “Player”, “Enemy” or “Bullet”, for Collider.IgnoreLayers and physics queries. Empty is the “Default” layer. (Names a collision layer: this entity’s own, which other fields can name.) (Field: a name.)
  • ignoreLayers: text = null. Layers this collider passes through, e.g. “Bullet, Enemy”: no blocking, no collisions, no triggers. It works both ways, so only one side has to list the other. (Names collision layers: their names, separated by commas.) (Field: a name.)

Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.

  • problem: text. What’s wrong with its Points and how it’s been fixed up, e.g. “Its sides cross each other, so it’s taken as the shape round all its points.”; null when they make a proper shape.
  • pieceCount: a whole number. How many convex pieces it’s made of: 1 for a convex shape, more for a concave one.
  • worldCentroid: [x, y]. Where it balances in the world: what it turns round.
  • turns: true or false. True when the shape turns with its entity: its Body (the entity’s own, or else the nearest one it’s inside) Body.Rotates. Otherwise it stays upright whatever the entity’s rotation, as colliders always have.

Scripts use it as PolygonCollider: its methods, events and values that aren’t saved with the scene.