Skip to content

Components

CharacterBody

A body that walks, jumps, falls and collides with the world. It climbs shallow steps, sticks to slopes going downhill, and reports whether it is standing on the floor, a wall or a ceiling.

On this page

Add it

+ Add node โ†’ Character, Root Motion Character creates a node with it already on. Already have a node for it? Add component โ†’ CharacterBodyComponent.

From a script

A script on the same node writes these fields by name. CharacterBodyComponent is the name to pass.

rgs
set_point("CharacterBodyComponent", "size", vec2(32.0, 48.0));
set_point("CharacterBodyComponent", "velocity", vec2(0.0, 0.0));
set_number("CharacterBodyComponent", "gravity", 1800.0);
set_number("CharacterBodyComponent", "terminal_velocity", 900.0);
set_number("CharacterBodyComponent", "speed", 220.0);
set_number("CharacterBodyComponent", "jump_speed", 620.0);
set_number("CharacterBodyComponent", "coyote_time", 0.0);
set_number("CharacterBodyComponent", "jump_buffer", 0.0);
set_number("CharacterBodyComponent", "jump_cut", 1.0);
set_number("CharacterBodyComponent", "swim_stroke", 0.0);
set_number("CharacterBodyComponent", "rope_jump", 0.0);
set_number("CharacterBodyComponent", "step_height", 0.0);
set_number("CharacterBodyComponent", "floor_snap_length", 0.0);
set_number("CharacterBodyComponent", "floor_max_angle", 0.7853982);
set_flag("CharacterBodyComponent", "pushable", false);
set_number("CharacterBodyComponent", "push_speed", 0.5);
set_flag("CharacterBodyComponent", "grounded", false);
set_flag("CharacterBodyComponent", "on_wall", false);
set_flag("CharacterBodyComponent", "shoving", false);
set_flag("CharacterBodyComponent", "on_ceiling", false);
set_flag("CharacterBodyComponent", "drop_through", false);
set_colour("CharacterBodyComponent", "debug_color", vec4(0.35, 0.85, 0.55, 0.35));

Fields

FieldScript nameKindDefaultWhat it does
Sizesizetwo numbers (x, y)(32, 48)Collision box size in world units, anchored at the feet.
Motion Modemotion_modeone of Grounded, FloatingGroundedGrounded: gravity pulls it down. Floating: no gravity, and every surface blocks it like a wall.
Driven Bydriven_byone of Keys, ScriptKeysKeys: the project's left and right actions walk it (A and D or the arrows, unless the Input window binds them otherwise; its move action, where it has a move and no left or right), turning it to face the way it walks, and its jump action (Space) jumps it when it is Grounded; up and down walk it the other two ways when it is Floating (move again, where it has neither). Script: its script sets its speed and calls jump().
Velocityvelocitytwo numbers (x, y)(0, 0)Current velocity, in units per second.
Driftdrifttwo numbers (x, y), read-only(0, 0)What the world adds to this body's own velocity: wind, a magnet, a belt, a current, a shove, a swing. Read only.
Gravitygravitynumber, at least 01800Positive; down counts as positive here.
Terminal Velocityterminal_velocitynumber, at least 1900Fastest the body may fall.
Speedspeednumber, at least 0220How fast the keys walk it; a script that drives it sets its own speed.
Jump Speedjump_speednumber, at least 0620Upward speed applied by a jump.
Jumping
Coyote Timecoyote_timenumber, at least 0, step 0.010Seconds after running off a ledge in which a jump still counts.
Jump Bufferjump_buffernumber, at least 0, step 0.010Seconds a jump asked for just before landing waits to happen on landing.
Jump Cutjump_cutnumber, 0 to 1, step 0.051How much of the rise is kept when the jump is let go early; 1 keeps all of it.
Air Jumpsair_jumpsnumber, 0 to 80How many more jumps it may make in the air before it lands again.
Swim Strokeswim_strokenumber, at least 0, step 100Upward speed a Jump press sets while the body's middle is under a Buoyancy waterline and it is neither grounded nor within its Coyote Time; 0 cannot swim.
Rope Jumprope_jumpnumber, at least 0, step 100Upward speed a Jump press sets while the body hangs on a rope โ€” held by an enabled joint, neither grounded nor within its Coyote Time; 0 cannot. It does not let go of the rope: the script that holds the joint does.
Slopes
Step Heightstep_heightnumber, at least 0, step 10Steps up to this height are climbed automatically, from the ground or by a body landing on it this step; a body in the air otherwise, or afloat, climbs onto nothing. Zero climbs none of them.
Floor Snap Lengthfloor_snap_lengthnumber, at least 0, step 10Keeps this body's feet on the ground going downhill; zero lets it launch off every step.
Floor Max Anglefloor_max_anglenumber, at least 0, step 0.010.7854In radians; anything steeper than this counts as a wall, not a floor.
Max Slidesmax_slidesnumber, 1 to 81How many times a blocked move is retried each step, so it can slide around corners.
Pushing
PushablepushablecheckboxoffA body that walks into this one shoves it along instead of stopping. It needs a solid Collider of its own to be walked into.
Push Speedpush_speednumber, 0 to 1, step 0.050.5How much of the pusher's speed a shove gives this body: 1 keeps pace with the pusher, 0.5 moves at half its speed.
GroundedgroundedcheckboxoffWhether something solid is directly below.
On Wallon_wallcheckboxoffHorizontal motion was blocked on the last step.
ShovingshovingcheckboxoffShoving a pushable body along on the last step. One that will not give way counts as a wall instead.
On Ceilingon_ceilingcheckboxoffUpward motion was blocked on the last step.
Drop Throughdrop_throughcheckboxoffIgnoring one-way platforms while leaving one: set and cleared in the step the body leaves the plank.
Layerlayernumber1Which physics layers this body is on.
Debug Colordebug_colorcolour#59d98c, 35% opaqueTint for the editor's debug box.