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)
2. Top-down 8-direction movement
3. Reading slide collisions after moving
4. Coyote time (forgiving jump just after leaving a ledge)
Pitfalls
- 3.x signature is gone.
move_and_slide(velocity)(returning the new velocity) was removed. In 4.x set thevelocityproperty and callmove_and_slide()with no args.move_and_slide(velocity, Vector2.UP)will not parse. - Multiplying velocity by delta.
move_and_slide()already accounts for the physics delta. Settingvelocity = dir * speed * deltamakes the body crawl. - Movement in
_processinstead of_physics_processcauses frame-rate-dependent, jittery motion. Always move in_physics_process. is_on_floor()always false whenup_directionis wrong (defaultVector2.UP), there is noCollisionShape2D, or you never calledmove_and_slide()this frame.- Sinking through floors usually means the collision shape is missing/zero-sized, the
floor body is on a layer this body's mask doesn't include, or you moved the body via
position +=instead of velocity +move_and_slide(). - Slope slipping while idle: keep
floor_stop_on_slope = true(default) and set afloor_snap_lengthso the body sticks to downward slopes.
References
- For one-way platforms, moving platforms, jump buffering, variable jump height, and
move_and_collide()(manual collision response), readreferences/controller-recipes.md.
Related skills
godot-physics— collision layers/masks, areas, raycasts, rigid bodies.godot-tilemap— building the levels this character walks on.godot-animation— driving sprite/skeletal animation from movement state.camera-systems— follow camera, deadzone, and look-ahead that track this character.platformer/input-systems— full genre template and rebindable input.


