
Godot 2d Movement
Implement 2D kinematic character movement in Godot 4.7 with CharacterBody2D and...
Install
npx skills add gamedev-skills/awesome-gamedev-agent-skills --skill godot-2d-movement -g -a claude-code -y- Repository
- gamedev-skills/awesome-gamedev-agent-skills6.4k
- Category
- Engineering
- Updated
- 8d ago
- License
- Apache-2.0
- Context cost
- Lightabout 1,457 tokens
- Runs scripts
- No, instructions only
What it does
Implement 2D kinematic character movement in Godot 4.7 with CharacterBody2D and move_and_slide(): platformer run/jump with gravity, top-down 8-direction motion, slope handling, and reading collisions. Use when coding a 2D player or enemy controller, a platformer or top-down character, or fixing move_and_slide()/ is_on_floor() behavior in a .tscn with a CharacterBody2D.
Godot 2D Movement (4.x)
Build responsive 2D character controllers with CharacterBody2D and the argument-less
move_and_slide(). Targets Godot 4.7.
When to use
- Use when scripting a 2D player/enemy that moves and collides: platformer (gravity + jump) or top-down (free 8-direction), slope walking, or wall/floor detection.
- Use when
move_and_slide()"does nothing", the character sinks through floors, oris_on_floor()is always false.
When not to use: dynamic rigid bodies, areas, raycasts, collision layers →
godot-physics; tile-based levels → godot-tilemap; full platformer game template →
the platformer genre skill; engine-agnostic feel tuning → physics-tuning.
Core workflow
- Use
CharacterBody2Dwith aCollisionShape2Dchild. It is script-driven: it does not fall or react to forces on its own. - Set the
velocityproperty, then callmove_and_slide()(no arguments in 4.x). The method readsvelocity, moves the body, slides along surfaces, and updatesvelocityto reflect what actually happened. - Do it in
_physics_process(delta),move_and_slide()uses the physics step's delta internally, so do not multiplyvelocitybydeltayourself. - Platformer: add gravity to
velocity.yeach tick, jump by settingvelocity.ynegative whenis_on_floor(). - Top-down: build a direction from input and scale by speed; set
motion_mode = MOTION_MODE_FLOATINGso there is no "floor/wall" distinction. - Read results with
is_on_floor(),is_on_wall(),get_wall_normal(), andget_slide_collision(i)after the call.
Patterns
1. Platformer controller (gravity, jump, slopes)
extends CharacterBody2D
@export var speed := 200.0
@export var jump_velocity := -400.0
@export var gravity := 1200.0 # pixels/sec^2 (tune to taste)
