$npx -y skills add thedivergentai/GD-Agentic-Skills --skill godot-characterbody-2dExpert 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 keyword
| 1 | # CharacterBody2D Implementation |
| 2 | |
| 3 | Expert guidance for player-controlled 2D movement using Godot's physics system. |
| 4 | |
| 5 | ## NEVER Do |
| 6 | |
| 7 | - **NEVER use `RigidBody2D` for standard player controllers** — RigidBody is for physics-simulated objects. For responsive, feel-driven player movement, always use `CharacterBody2D`. |
| 8 | - **NEVER multiply `velocity` by `delta` before `move_and_slide()`** — `move_and_slide()` handles delta internally. Manual multiplication makes movement framerate-dependent [12]. |
| 9 | - **NEVER use `global_position` updates for movement** — Use `velocity` and `move_and_slide()`. Direct position updates bypass collision detection and floor snapping. |
| 10 | - **NEVER ignore the return value of `move_and_slide()`** — While optional, checking `is_on_floor()` or `get_last_motion()` immediately after is critical for state logic. |
| 11 | - **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 for smooth transitions. |
| 12 | - **NEVER apply gravity while `is_on_floor()` is true** — Constant downward force on the floor can cause "micro-jitter" or prevent floor-snap from working correctly. Reset `velocity.y` to 0 or a small constant. |
| 13 | - **NEVER use `Area2D` for ground detection** — Real collisions (rays/shapecasts) are more precise. `is_on_floor()` is highly optimized; only augment it if necessary. |
| 14 | - **NEVER forget Ceiling Bonk detection** — If you don't reset `velocity.y` to 0 when `is_on_ceiling()`, the player will "float" against the ceiling until gravity pulls them down. |
| 15 | - **NEVER use high-precision physics for pixel art visuals** — Keep physics math high-precision, but round your Sprite nodal positions in `_process` to avoid visual sub-pixel jitter. |
| 16 | - **NEVER use `queue_free()` on characters every frame** — Use object pooling for bullets or enemies to avoid SceneTree performance spikes. |
| 17 | --- |
| 18 | |
| 19 | ## Godot 4.7: CharacterBody2D |
| 20 | |
| 21 | - Jolt 3D changes do not apply to 2D, but one-way **direction** on `CollisionShape2D` affects platformer feel — align with movement normals. |
| 22 | |
| 23 | ## Available Scripts |
| 24 | |
| 25 | > **MANDATORY**: Read the appropriate script before implementing the corresponding pattern. |
| 26 | |
| 27 | ### [frame_perfect_coyote_time.gd](scripts/frame_perfect_coyote_time.gd) |
| 28 | Professional platformer mechanics: Coyote Time (jump after fall) and Input Buffering. |
| 29 | |
| 30 | ### [slope_stair_snapping.gd](scripts/slope_stair_snapping.gd) |
| 31 | Advanced procedural stair-climbing and smooth slope snapping logic. |
| 32 | |
| 33 | ### [variable_jump_height.gd](scripts/variable_jump_height.gd) |
| 34 | Customizable 'Short Hop' vs 'Full Jump' implementation based on input duration. |
| 35 | |
| 36 | ### [wall_slide_jump_refined.gd](scripts/wall_slide_jump_refined.gd) |
| 37 | Responsive Wall Slide and Wall Jump mechanics with proper push-back forces. |
| 38 | |
| 39 | ### [dash_state_controller.gd](scripts/dash_state_controller.gd) |
| 40 | State-based dash logic with invincibility frames and customizable cooldowns. |
| 41 | |
| 42 | ### [subpixel_movement_rounding.gd](scripts/subpixel_movement_rounding.gd) |
| 43 | Expert pattern for maintaining pixel-perfect visuals in low-res games while keeping smooth physics. |
| 44 | |
| 45 | ### [performance_character_pooling.gd](scripts/performance_character_pooling.gd) |
| 46 | Logic for optimizing 100+ active characters using visibility-based physics toggling. |
| 47 | |
| 48 | ### [impulse_response_handler.gd](scripts/impulse_response_handler.gd) |
| 49 | Expert handling of external forces (Knockback, Blow-back, Wind) integrated with `move_and_slide`. |
| 50 | |
| 51 | ### [aerial_drift_acceleration.gd](scripts/aerial_drift_acceleration.gd) |
| 52 | Precise air control and acceleration logic for professional platformer feel. |
| 53 | |
| 54 | ### [ceiling_bonk_detection.gd](scripts/ceiling_bonk_detection.gd) |
| 55 | Fixing 'sticky head' syndrome by correctly handling vertical momentum on ceiling hits. |
| 56 | |
| 57 | ### [expert_physics_2d.gd](scripts/expert_physics_2d.gd) |
| 58 | Complete platformer movement with coyote time, jump buffering, smooth acceleration/friction, and sub-pixel stabilization. Uses move_toward for precise control. |
| 59 | |
| 60 | ### [dash_controller.gd](scripts/dash_controller.gd) |
| 61 | Frame-perfect dash with I-frames, cooldown, and momentum preservation. |
| 62 | |
| 63 | ### [wall_jump_controller.gd](scripts/wall_jump_controller.gd) |
| 64 | Wall slide, cling, and directional wall jump with auto-correction. |
| 65 | |
| 66 | > **Do First**: Read expert_physics_2d.gd for platformer foundation before adding dash/wall-jump. |
| 67 | |
| 68 | --- |
| 69 | |
| 70 | ## When to Use CharacterBody2D |
| 71 | |
| 72 | **Use CharacterBody2D For:** |
| 73 | - Player characters (platformer, top-down, side-scroller) |
| 74 | - NPCs with custom movement logic |
| 75 | - Enemies with non-physics-based movement |
| 76 | |
| 77 | **Use RigidB |