Skip to content
Back to skills

Godot 2d Rig

ASecurity

A layered 2D character into Godot: rig2d.json to Skeleton2D, Bone2D and weighted Polygon2D parts, cut-out animation, 2D IK.

  • 5 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
ai-agentspythonrustgobashnodeawsapi

Works with

  • api

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned December 3, 2026

npx -y skills add tipoLi5890/game-studio --skill godot-2d-rig --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Godot 2d Rig?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Godot 2d Rig
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tipoli5890-godot-2d-rig/badge)](https://www.skillsdirectory.com/skills/tipoli5890-godot-2d-rig)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: godot-2d-rig
description: >-
  A layered 2D character into Godot: rig2d.json to Skeleton2D, Bone2D and weighted Polygon2D
  parts, cut-out animation, 2D IK.
---

# godot-2d-rig — a layered 2D character from game-assets, in Godot

A `rig2d/1` file becomes a `Skeleton2D` with `Bone2D` nodes and weighted `Polygon2D` parts, one
per layer, drawn in the layer order and standing on the node's position.

## Load what the situation needs

| The situation | Read |
|---|---|
| A layered character (`rig2d.json` and layer PNGs) from `comfyui-asset-generation`; "rig this in Godot" | *The conversion* below, then `reference/rig2d-mapping.md` §1-3 |
| Which way y goes, where the origin is, why a bone points the wrong way | `reference/rig2d-mapping.md` §2 |
| Skinned mesh parts or stiff cut-out sprites | `reference/rig2d-mapping.md` §3 |
| An arm drawn behind the torso; parts interleaving with the world | `reference/rig2d-mapping.md` §4 |
| Blinking, mouth shapes: switching swap states | `reference/rig2d-mapping.md` §5 |
| The head turn, gaze, an idle sway from the rig's own data | `reference/rig2d-mapping.md` §6 |
| Animating bones with an `AnimationPlayer` | `reference/rig2d-mapping.md` §7 |
| A hand reaching a target, feet planted: 2D IK | `reference/ik-2d.md` |
| Building the character at runtime from the JSON; checking a rig in the engine | `resources/rig2d_builder.gd` · `reference/rig2d-mapping.md` §8 |
| Frame-by-frame sprites instead of bones | `godot-2d-sprites` |
| Blend trees and state machines over the bone animations | `godot-animation` |

## The conversion

```bash
python3 scripts/rig2d_to_scene.py game/art/courier/rig/rig2d.json \
    --out game/art/courier/courier_rig.tscn --name Courier
python3 scripts/rig2d_to_scene.py game/art/courier/rig/rig2d.json --mode cutout \
    --out game/art/courier/courier_cutout.tscn
python3 scripts/rig2d_to_scene.py game/art/courier/rig/rig2d.json --check-only
```

The scene it writes (no Godot needed to convert; import the project once afterwards so the layer
PNGs load):

```
Courier (Node2D)            metadata: rig2d_origin, rig2d_view, rig2d_swaps, rig2d_face, rig2d_sway
├── Skeleton2D
│   └── hips (Bone2D)        └── chest ── head, upperarm_R ── forearm_R ── hand_R, ...
└── Parts (Node2D)          one Polygon2D per layer, bottom layer first
    ├── leg_L ... torso ... head ... eyes_closed (hidden) ... arm_R
```

Exit codes: 0 written (or `--check-only` passed) · 2 the rig failed a check, each problem on a
`FAIL` line, nothing written · 1 a usage error, a stamp other than `rig2d/1`, a `rig2d/1` file
missing a required key · 3 a missing or unreadable file (a layer PNG).

## The conversion, decided

1. **Nothing flips.** rig2d/1 is canvas pixels, y down; so is Godot 2D, in pixels. The only
   change of frame is the origin: `--origin ground` (default) puts the root bone's x and the
   lowest vertex on the node's position, so the courier stands where it is placed.
2. **Bones carry no rotation at rest.** Each `Bone2D` sits at its head relative to its parent's
   head, with `rest` equal to that transform; `length` and `bone_angle` come from head to tail
   with auto-calculation off. In the scene text `bone_angle` is degrees; through the API it is
   radians.
3. **Weights become dense.** rig2d's `bw` holds two (bone, weight) pairs per vertex; each
   `Polygon2D` gets one weight array per bone, as long as its vertex list, bones named by path
   relative to the `Skeleton2D`. Weights must sum to 1 per vertex (checked).
4. **The layer order becomes the tree order.** `layers` runs top to bottom and Godot draws later
   siblings on top, so parts are written bottom first. Cut-out sprites, spread over bones, use
   `z_index` instead.
5. **Swap states are siblings, one visible.** The first state of each category shows; the
   others are hidden; `set_swap()` switches by label.
6. **The checks run before anything is written**: bones exist and form a tree, each part names
   1-8 real bones and is a layer, vertices are pairs inside the canvas, indices are triangles of
   the part's own vertices, `bw` has two pairs per vertex.

## Using the rig

```gdscript
extends Node2D
const Rig2D = preload("res://tools/rig2d_builder.gd")
@onready var courier: Node2D = $Courier

func _ready() -> void:
	var problems := Rig2D.check(courier)          # rest set, bone paths, weights, rest pose
	assert(problems.is_empty(), "\n".join(problems))
	var lib := AnimationLibrary.new()
	lib.add_animation(&"idle", Rig2D.sway_idle(courier))
	var player := AnimationPlayer.new()             # a child of the root: tracks are relative to it
	courier.add_child(player)
	player.add_animation_library(&"", lib)
	player.play(&"idle")
	Rig2D.add_two_bone_ik($Courier/Skeleton2D, NodePath("hips/chest/upperarm_R"),
		NodePath("hips/chest/upperarm_R/forearm_R"), NodePath("../HandTarget"))

func blink() -> void:
	Rig2D.set_swap(courier, "eyes", "closed")
	await get_tree().create_timer(0.12).timeout
	Rig2D.set_swap(courier, "eyes", "open")
```

`Rig2D.build("res://art/courier/rig/rig2d.json")` builds the same tree in the engine (mesh
parts), for characters loaded at runtime; the selftest checks that it matches the converter's
scene bone for bone and weight for weight.

## Checking it headless

- `rig2d_to_scene.py --check-only` on the JSON, before any Godot run.
- Load the scene in a `-s` run, add it to the tree, wait a frame, and read: the
  `Skeleton2D.get_bone_count`, each bone's global position against its head minus the origin,
  `Bone2D.get_bone_angle` against the head-to-tail angle, the order of the Parts node's children
  against `layers` reversed, and the builder's `check()` empty.
- IK and animation are transforms, so they are observable: the forearm's end reaches its target;
  `AnimationPlayer.advance` moves a swayed bone to the angle the formula gives.
- What is not observable headless: the skinned deformation and the drawn result. The rest-pose
  check proves the data that drives the deformation (every vertex plus the origin is its layer
  pixel), not the pixels on screen.

`scripts/rig2d_to_scene.py --selftest` (needs `GODOT_BIN`) does all of the above on a small
courier: both modes, the in-engine builder, swaps, IK, the sway idle, and each check failing with
its exit code. Trust a Godot run by its sentinel line and the absence of `ERROR:` lines, never by
its exit code (`godot-verify`).

## Discipline

- **Never rename a layer in Godot.** The layer name ties the PNG, the part and the swap together;
  rename on the asset side and convert again.
- **Animate rotations, not positions,** for limbs; positions stretch the weighted parts.
- **Animate IK targets, not IK-driven bones.**
- **Keep the converter's output generated.** Hand edits to bones or weights are lost on the next
  conversion; change the source rig, or layer an override scene on top (an inherited scene).
- **One origin per character,** the same for every rig of it, so swapping rigs keeps the feet.

## Related skills

| Need | Skill |
|---|---|
| The layered character itself: layers, bones, weights, the split's gates | `comfyui-asset-generation` |
| Which track a character takes (frames or a rig) | `game-character-pipeline` |
| Frame animation | `godot-2d-sprites` |
| Animation trees, blending, state machines | `godot-animation` |
| Draw order with the rest of the world, 2D lights | `godot-2d-rendering` |
| Running Godot headless and trusting the result | `godot-verify` |

Files in this skill

  • SKILL.md7.3 KB
  • reference/ik-2d.md4.4 KB
  • reference/rig2d-mapping.md8.6 KB
  • resources/rig2d_builder.gd9.9 KB
  • scripts/rig2d_to_scene.py34.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.