Skip to main content

character2d

2d · physics · 12 properties · 2D

Moves a node the way a 2D player expects: physics2d.move_character slides it along walls, steps it up ledges, keeps it off slopes that are too steep and holds it to the ground over a crest. Needs a collider2d.

In a scene, character2d is the node key that applies it. A script reaches the same properties through node.character2d.get() and node.character2d.set(table).

Properties

propertytypedefaultdescription
autostepfloat0.3The tallest step the character climbs without jumping; 0 turns stepping off At least 0.
autostep_dynamicboolfalseClimb onto dynamic bodies too, not only static and kinematic ones
autostep_min_widthfloat0.2How much clear ground a step needs on top before it may be climbed At least 0.
lengthsenumabsoluteWhether offset, autostep and snap_to_ground are in world units or as a fraction of the character's own height One of absolute, relative.
max_climb_anglefloat45The steepest slope the character may walk up, in degrees Range 0–90.
min_slide_anglefloat30The shallowest slope the character slides back down, in degrees Range 0–90.
normal_nudgefloat0.0001A tiny push along the contact normal that stops the character catching on seams At least 0.
offsetfloat0.01A gap kept between the character and everything else, so the solver never has to push it out of a wall At least 0.
push_bodiesbooltruePush dynamic bodies the character walks into, rather than passing through them
slidebooltrueSlide along what is in the way instead of stopping dead against it
snap_to_groundfloat0.2How far below its feet the character looks for ground to stay stuck to over a crest; 0 turns snapping off At least 0.
upvec2[0,1]Which way is up for this character: the axis it stands along and measures slopes against

Script functions

Methods of node.character2d, the handle a node carrying this component exposes. Each is also a free function on its module, taking the node as its first argument. Every handle also has get(), set(table), has() and remove().

From physics2d:

methodwhat it does
is_grounded() -> boolWhether the last move ended with ground under the character's feet.
move_character(float, float) -> anyMove the character by an offset, sliding along walls, climbing steps and staying on the ground: returns #{ x, y, grounded, sliding, collisions }. Call it from fixed_update.