The Polygon Collider 2D component is a Collider for use with 2D physics. The Collider’s shape is defined by a freeform edge made of line segments, so you can adjust it to fit the shape of the Sprite graphic with great precision. Note that this Collider’s edge must completely enclose an area (unlike the similar Edge Collider 2D).
Property | Function |
---|---|
Material | Физический материал, который определяет свойства коллизий, такие как трение и отскок. |
Is Trigger | Tick this box if you want the Collider to behave as a trigger. |
Used by Effector | Whether the Collider is used by an attached effector or not. |
Used by Composite | Tick this checkbox if you want this Collider to be used by an attached Composite Collider 2D. When you enable Used by Composite, other properties disappear from the Polygon Collider 2D component, because they are now controlled by the attached Composite Collider 2D. The properties that disappear from the Box Collider 2D are Material, Is Trigger, Used By Effector, and Edge Radius. |
Used by Collider | Check this box if you want the Box Collider 2D to be used by an attached Composite Collider 2D component. |
Auto Tiling | Tick this checkbox if you have set the Draw Mode of the Sprite Renderer component to Tiled. This enables automatic updates to the shape of the Collider 2D, meaning that the shape is automatically readjusted when the Sprite’s dimensions change. If you don’t enable Auto Tiling, the Collider 2D stays the same shape and size, even when the Sprite’s dimensions change. |
Offset | The local offset of the Collider geometry. |
Points | Non-editable information about the complexity of the generated Collider. |
The Collider can be edited manually but it is often more convenient to let Unity determine the shape automatically. You can do this by dragging a Sprite Asset from the Project view onto the Polygon Collider 2D component in the Inspector.
You can edit the polygon’s shape by pressing the Edit Collider button in the Inspector. You can exit Collider edit mode by pressing the Edit Collider button again. While in edit mode, you can move an existing vertex by dragging when the mouse is over that vertex. If you shift-drag while the mouse is over an edge, a new vertex will be created at the mouse location. You can remove a vertex by holding down the ctrl/cmd key while clicking on it.
Note that you can hide the outline of the 2D move Gizmo while editing the Collider - just click the fold-out arrow on the Sprite Renderer component in the Inspector to collapse it.