godot-characterbody-2d
Expert patterns for CharacterBody2D including platformer movement (coyote time, jump buffering, variable jump height), top-down movement (8-way, tank controls), collision handling, one-way platforms, and state machines. Use for player characters, NPCs, or enemies. Trigger keywords: CharacterBody2D,
By thedivergentai · 391 installs
npx skills add thedivergentai/gd-agentic-skills --skill godot-characterbody-2d
Source repository · Upstream listing
CharacterBody2D Implementation
Expert CharacterBody2D feel systems — not beginner move and slide tutorials.
NEVER Do
NEVER use RigidBody2D for standard player controllers — RigidBody is for physics simulated objects. For responsive, feel driven player movement, always use CharacterBody2D .
NEVER multiply velocity by delta before move and slide() — move and slide() handles delta internally. Manual multiplication makes movement framerate dependent.
NEVER use global position updates for gameplay movement — Use velocity + move and slide() . Direct position hacks bypass collision, floor snap, and one way rules.
NEVER "fall through" one ways by nudging position.y — Use one way collision shapes + layer/mask (and temporary mask disable / collide with areas patterns). See [godot 2d physics](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot 2d physics/SKILL.md).
NEVER ignore floor/wall/ceiling state right after move and slide() — is on floor() , is on wall() , is on ceiling() , and slide collisions drive coyote, wall jump, and bonk logic.
NEVER rely on default floor snap length for fast stair climbing — Default snapping is too small for high velocity characters. Use custom raycast based stair logic.
NEVER apply gravity while is on floor() is true — Constant downward force causes micro jitter and fights floor snap. Reset velocity.y on land.
NEVER use Area2D as primary ground detection — Prefer is on floor() / shapecasts; Areas are for triggers, not floor truth.
NEVER forget ceiling bonk — Reset velocity.y when is on ceiling() or the player floats into the ceiling until gravity wins.
NEVER round physics positions for pixel art — Keep physics high precision; round sprite positions in process only ([subpixel movement rounding.gd](scripts/subpixel movement rounding.gd)).
NEVER spam queue free() for hordes — Pool bullets/enemies when spawn/despawn is frequent ([performance character pooling.gd](scripts/performance character pooling.gd)).
When to Use CharacterBody2D
Need Body
Feel driven player / NPC / enemy locomotion CharacterBody2D
Rolling debris, ragdoll ish props, force piles RigidBody2D
Static level colliders StaticBody2D / TileMapLayer physics
Decision Tree → MANDATORY Scripts
Task Do First Then (optional) Do NOT Load
Platformer foundation (coyote, buffer, accel/friction) [expert physics 2d.gd](scripts/expert physics 2d.gd) — Inline tutorial controllers
Isolate coyote/buffer only [frame perfect coyote time.gd](scripts/frame perfect coyote time.gd) — Duplicate coyote blocks in SKILL
Variable jump / short hop [variable jump height.gd](scripts/variable jump height.gd) — —
Slopes / stairs [slope stair snapping.gd](scripts/slope stair snapping.gd) [godot raycasting queries](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot raycasting queries/SKILL.md) —
Wall slide / wall jump [wall slide jump refined.gd](scripts/wall slide jump refined.gd) or [wall jump controller.gd](scripts/wall jump controller.gd) — Both unless comparing
Dash + i frames [dash state controller.gd](scripts/dash state controller.gd) or [dash controller.gd](scripts/dash controller.gd) — Both unless comparing
Air control polish [aerial drift acceleration.gd](scripts/aerial drift acceleration.gd) — —
Ceiling stick / bonk [ceiling bonk detection.gd](scripts/ceiling bonk detection.gd) — —
Knockback / wind impulses [impulse response handler.gd](scripts/impulse response handler.gd) — —
Pixel art visuals [subpixel movement rounding.gd](scripts/subpixel movement rounding.gd) — Rounding global position in physics
Many AI bodies [performance character pooling.gd](scripts/performance character pooling.gd) — —
One way platforms Tile/StaticBody one way + layers/masks [godot tilemap mastery](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot tilemap mastery/SKILL.md) / [godot 2d physics](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot 2d physics/SKILL.md) position.y += 1 drop through hacks
Top down / tank locomotion [movement recipes.md](references/movement recipes.md) — Inline 8 way tutorials
Jump arc debug tuning [game feel profiler.gd](scripts/game feel profiler.gd) — —
Animation root motion [root motion controller.gd](scripts/root motion controller.gd) [godot 2d animation](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot 2d animation/SKILL.md) —
Golden path: Read expert physics 2d.gd first. Add dash/wall/jump scripts only after that controller is in place. Do not re inline coyote/buffer/accel loops in the scene when the script already owns them.
One Way Platforms (correct recipe)
1. Author one way on the platform collider ( CollisionShape2D one way / TileSet physics one way), not by teleporting the player.
2. Put platforms and player on explicit collision layers/masks so drop through can temporarily clear the platform bit (or disable collide with) while holding down + jump — then restore next physics frames.
3. Keep drop through on the physics tick ; never bypass move and slide with position nudges.
4. For tile one ways, align TileSet physics layers with CharacterBody masks — see [godot tilemap mastery](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot tilemap mastery/SKILL.md) + [godot 2d physics](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot 2d physics/SKILL.md).
Expert Character Architectures
1. Wall Cling (Variable Friction)
Monitor is on wall() while falling; scale velocity.y by a friction factor (optionally from tile custom data) instead of a binary wall slide bool. Prefer [wall slide jump refined.gd](scripts/wall slide jump refined.gd) over a bespoke cling fork.
2. Animation Driven Movement (Root Motion)
Pull AnimationTree.get root motion position() , convert to 2D, assign velocity = motion / delta , then move and slide() . Keeps feet locked to authored clips; pair with [godot 2d animation](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot 2d animation/SKILL.md).
3. Game Feel Profiler (Jump Arcs)
Debug draw historical positions + current velocity in draw() to visualize apex, coyote, and buffer windows while tuning exports on expert physics 2d.gd — [game feel profiler.gd](scripts/game feel profiler.gd).
MANDATORY for top down/tank recipes, moving platforms, slide collision response, and gotcha tables: [movement recipes.md](references/movement recipes.md). Do NOT Load when expert physics 2d.gd already covers your platformer scope.
Reference
Progressive disclosure: open Official Documentation links only when researching a specific API;
load Related Skills when routing work to a peer domain — do not preload the whole lattice.
Official Documentation
[Using CharacterBody2D](https://docs.godotengine.org/en/stable/tutorials/physics/using character body 2d.html) — Canonical move and slide / floor wall ceiling contracts; do not set position for gameplay motion.
[CharacterBody2D](https://docs.godotengine.org/en/stable/classes/class characterbody2d.html) — API for velocity , snap, is on floor / wall / ceiling, and slide collision accessors.
[Physics introduction](https://docs.godotengine.org/en/stable/tutorials/physics/physics introduction.html) — Why CharacterBody vs RigidBody/StaticBody, and how layers/masks gate every contact.
[Collision shapes (2D)](https://docs.godotengine.org/en/stable/tutorials/physics/collision shapes 2d.html) — Capsule/box sizing and why scaled CollisionShape2D nodes corrupt normals and floor detect.
[2D movement](https://docs.godotengine.org/en/stable/tutorials/2d/2d movement.html) — Input axes into velocity for top down and platformer starters before juice systems.
[Kinematic character (2D)](https://docs.godotengine.org/en/stable/tutorials/physics/kinematic character 2d.html) — Classic slide/collision loop patterns that still inform custom stair and slope handling.
[Troubleshooting physics issues](https://docs.godotengine.org/en/stable/tutorials/physics/troubleshooting physics issues.html) — One way platforms, tunneling, and jitter diagnoses that show up in CharacterBody feel bugs.
[Ray casting](https://docs.godotengine.org/en/stable/tutorials/physics/ray casting.html) — Direct space rays for stair snaps, ledge checks, and ground probes beyond is on floor() .
[KinematicCollision2D](https://docs.godotengine.org/en/stable/classes/class kinematiccollision2d.html) — Per slide normals/remainders from get slide collision for wall jumps and ceiling bonks.
[Physics interpolation introduction](https://docs.godotengine.org/en/stable/tutorials/physics/interpolation/physics interpolation introduction.html) — Smooth visuals at high refresh while keeping jump/coyote logic on the physics tick.
[InputEvent](https://docs.godotengine.org/en/stable/tutorials/inputs/inputevent.html) — Action just pressed timing that jump buffers and coyote windows depend on.
Related Skills
Prerequisites
[godot project foundations](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot project foundations/SKILL.md) — Default gravity, physics tick rate, and 2D layer names must be set before coyote/jump feel is tunable.
[godot gdscript mastery](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot gdscript mastery/SKILL.md) — Typed physics process , timers, and move toward discipline underpin every movement script here.
[godot 2d physics](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot 2d physics/SKILL.md) — Collision layer/mask matrices, one way shapes, and query hygiene CharacterBody motion sits on.
[godot input handling](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot input handling/SKILL.md) — Physics step action sampling so jump buffer / coyote windows stay frame stable.
Complements
[godot raycasting queries](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot raycasting queries/SKILL.md) — Stair snaps, wall cling probes, and ledge rays that extend beyond is on helpers.
[godot tilemap mastery](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot tilemap mastery/SKILL.md) — One way tiles and tile physics layers must match CharacterBody masks for platforms.
[godot 2d animation](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot 2d animation/SKILL.md) — Drive walk/jump/fall clips from floor/air/dash state without fighting move and slide .
[godot state machine advanced](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot state machine advanced/SKILL.md) — Dash, wall slide, and airborne states scale cleaner than giant physics process switches.
[godot camera systems](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot camera systems/SKILL.md) — Follow/look ahead cameras couple tightly to CharacterBody velocity and landing snaps.
[godot signal architecture](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot signal architecture/SKILL.md) — Landed/dashed/wall jumped events need clean ownership so UI/VFX listeners do not spam.
Downstream / consumers
[godot genre platformer](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot genre platformer/SKILL.md) — Genre level platformer feel consumes coyote, buffer, slopes, and one ways from this skill.
[godot genre metroidvania](https://github.com/thedivergentai/gd agentic skills/blob/main/skills/godot genre metroidvania/SKILL.md) — Ability gated movement (wall jump, dash) builds on the controllers defined here.
[godot comb