Overview
When creating players or enemy characters in Godot, CharacterBody2D is likely the first node most people use. This node provides the convenient move_and_slide() function for physics-based movement, but there's an important property that significantly affects its behavior: "Motion Mode."
Motion Mode has two main types: Grounded and Floating. Using these correctly makes it easy to achieve optimal character behavior for the type of game you want to create.
This article explains the differences in CharacterBody2D's Motion Modes and which games each mode is best suited for.
What is Motion Mode?
Motion Mode is a setting that determines how a CharacterBody2D behaves in physical space, specifically how it interprets "floors" and "walls." You can configure it from the CharacterBody2D properties in the Inspector.
| Mode | Key Features | Best Game Types |
|---|---|---|
| Grounded | (Ground mode) Affected by gravity, recognizes floors, walls, and ceilings. Convenient functions like is_on_floor() are available. | Side-scrolling platformers, action games |
| Floating | (Float mode) Ignores gravity, has no floor concept. Treats collisions from all directions equally. | Top-down action, shooters, RPGs |
Grounded Mode: The Standard for Side-Scrollers
Grounded is the default mode for CharacterBody2D and assumes character behavior with "feet on the ground."
Features:
- Gravity is Fundamental: Gravity defined in project settings automatically affects the character
- Floor Detection: The
is_on_floor()function is available, making it easy to check if the character is touching the ground. This makes it easy to prevent multi-jumping while airborne - Handles Slopes:
move_and_slide()automatically adjusts for smooth slope navigation
This mode is the optimal choice for Mario-style side-scrolling action and almost any 2D game where gravity plays an important role.
# Typical code for Grounded Mode
func _physics_process(delta):
# Apply gravity
if not is_on_floor():
velocity.y += gravity * delta
# Jump
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
# ...movement processing...
move_and_slide()
Floating Mode: Partner for Top-Down Games
On the other hand, Floating mode assumes behavior where the character floats freely like a spaceship or ghost.
Features:
- Gravity Irrelevant: In this mode, gravity is not automatically applied. The character stays still when
velocityisVector2.ZERO - No Floor Concept:
is_on_floor()always returnsfalse. All collisions are treated simply as "wall" collisions - Movement in All Directions: Suitable for logic where movement is equal in up, down, left, and right directions
This is optimal for top-down RPGs like The Legend of Zelda, twin-stick shooters, and other games where characters move freely around the map without being bound to the ground.
# Typical code for Floating Mode
func _physics_process(delta):
# Determine movement direction from input
var direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
velocity = direction * SPEED
# ...other processing...
move_and_slide()
Notice how the gravity and is_on_floor() checks from the Grounded mode code are unnecessary, making it very simple.
Summary
CharacterBody2D's Motion Mode is an important setting for switching the foundation of character physics behavior to match your game's genre.
- Building a side-scroller or platformer → Grounded Mode
- Building a top-down RPG or shooter → Floating Mode
Setting this correctly from the start makes subsequent character movement coding dramatically smoother. Choose the optimal mode for the game you want to create and enjoy comfortable Godot development.