extract_collision_polygon
Extracts a simplified outer collision polygon from opaque sprite pixels for static props and irregular scenery, returning points and a ready-to-paste CollisionPolygon2D snippet.
Instructions
Extract a simplified outer collision polygon from opaque pixels.
This optional tool is intended for static objects and irregular scenery. For moving characters and monsters, use build_body_collider instead to get a stable feet-aligned RectangleShape2D or CapsuleShape2D.
The largest external alpha contour is traced and simplified with the Ramer-Douglas-Peucker algorithm. The result is a simple clockwise polygon with at most 24 vertices, suitable for a CollisionPolygon2D.
Args:
image_path: Absolute path, relative path, or res:// URI to a PNG.
region: Optional sub-region {"x": int, "y": int, "w": int, "h": int}
in image pixels. When omitted, the whole image is used. Returned
coordinates are relative to this region's top-left corner.
epsilon: RDP simplification tolerance in pixels. Defaults to 2.0.
Larger values produce fewer vertices. If necessary the tolerance
is increased internally to keep the polygon at or below 24
vertices.
centered: When true (the default, matching Godot 4 Sprite2D), every
point is shifted so the coordinate origin is the image/region
centre. For a region of size w x h the conversion is
x - w / 2 and y - h / 2. Set to false to keep pixel-space
coordinates with a top-left origin.
project_root: Optional Godot project root directory for resolving
res:// URIs.
Returns:
A dictionary with points (list of [x, y]), vertex_count,
packed_vector2_array (Godot text such as
PackedVector2Array(0.0, -16.0, ...)) and tscn_snippet (a
CollisionPolygon2D node block ready to paste into a .tscn file).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| region | No | ||
| epsilon | No | ||
| centered | No | ||
| image_path | Yes | ||
| project_root | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||