Skip to main content

Polygon Collider 2D

The Polygon Collider 2D component enables accurate collision detection for 2D images by defining custom polygonal boundaries. You can customize the shape by manually editing vertices to adapt to complex designs, ensuring optimal collision accuracy. By customizing its features and parameters, you can adapt it to a wide range of use cases, from interactive games to complex physics simulations.

polygon collider demo

Add a Polygon Collider 2D Component

To add a Polygon Collider 2D component:

  1. Go to the Hierarchy panel
  2. Add or select a 2D object and locate its components in the Inspector panel
  3. Click Add component
  4. Go to 2D Physics
  5. Select Polygon Collider 2D
polygon collider demo

Properties

PropertyDescription
Enable EditingAllows you to enter Edit Mode to adjust the vertices of the polygon collider directly in the Scene panel. Drag endpoints to reshape or create new edges by moving the cursor perpendicular to the existing line segments.
Point XDefines a corner or edge of the polygon, and its position directly impacts the collider's shape. If you are in Edit Mode, the points' X and Y values automatically update.
Physics MatterSpecifies a physics material to determine the collider's physical properties, such as:
  • Friction: Controls how surfaces interact during sliding or contact
  • Elasticity: Determines the "bounciness" of collisions

Assigning a physics material enables realistic physical behavior tailored to the needs of your project.

Is TangibleWhen selected, the collider becomes a trigger. Does not physically block objects but detects events like when an object enters, remains in, or exits the collider. Useful for interactions that don’t require physical barriers, such as detecting zones or non-physical effects.
Show ColliderEnables the visibility of the collider's outline in the Edit Mode. When enabled, the collider's shape and adjustments are displayed as an overlay on the object, helping with:
  • Debugging and refining shapes
  • Verifying alignment with the intended 2D image

Does not affect collider functionality during runtime; it is purely an editor aid.

polygon collider properties

Use Edit Mode

Edit Mode in the Polygon Collider 2D component allows precise customization of the collider's shape by directly manipulating its vertices and edges. This feature is essential for aligning the collider with complex 2D image boundaries, ensuring accurate collision detection.

Enter Edit Mode

To enter Edit Mode:

  1. Select the object with the Polygon Collider 2D component
  2. Navigate to the Inspector panel and locate the component
  3. Select the Enable Editing checkbox
edit mode

Features and Operations in Edit Mode

The following outlines the different operations that can be performed in Edit Mode:

Manipulate Vertices

  • Move vertices: Drag any vertex to adjust its position. The changes update in real time in the Points properties of the component.
  • Add vertices: Dragging along a line segment perpendicular to its direction creates a new vertex. New vertices automatically appear in the Points list.
  • Delete vertices: Vertices cannot be removed by dragging them back into a straight line. Once created, they persist. Reset the component to clear manipulations.

Adjust Edges

  • Length and rotation: Dragging vertices alters the connected edges, allowing you to reshape the polygon
  • Snapping: Vertices snap to nearby points when within 0.1 units, ensuring precision

Collision Feedback

  • Edge intersections: Intersecting edges turn red as a warning

Grip Points

  • Gizmo handles: Handles appear near edges and vertices, allowing for intuitive adjustments
  • Real-time updates: All movements and changes are reflected immediately in the collider's shape

Tips for Using Edit Mode

Refer to the following best practices when using Edit Mode:

  • Simplify shapes: Keep the number of vertices to a minimum for optimal performance
  • Align precisely: Use snapping to align vertices with specific points in the 2D object
  • Test regularly: Switch between Edit Mode and real-time testing to validate the collider’s behavior
  • Avoid intersections: Resolve red-highlighted edges to prevent unexpected simulation issues