character2d component
A 2D character controller: physics2d.move_character slides the node along walls and steps it up ledges. Needs a collider2d; a kinematic body2d lets it…
На этой странице
2d · physics · 18 properties · 2D
A 2D character controller: physics2d.move_character slides the node along walls and steps it up ledges. Needs a collider2d; a kinematic body2d lets it push bodies.
In a scene, character2d is the node key that applies it. A script reaches each property below as a field on node.character2d: reading one asks the running component, and assigning one leaves the rest alone. The whole table is node.character2d.get() and node.character2d.set(table).
Properties
| property | type | default | description |
|---|---|---|---|
floor_max_angle |
float | 0.7853982 |
The steepest slope the character may walk up; radians in the file, degrees in the inspector Range 0–90. |
floor_snap_length |
float | 0.2 |
How far below its feet the character looks for ground to stay stuck to over a crest; 0 turns snapping off At least 0. |
floor_snap_lengths |
enum | absolute |
Whether floor_snap_length is in world units or a fraction of the character's shape: relative is measured against the height along up_direction One of absolute, relative. |
ignore |
flags | ["sensors"] |
What a move passes through: static takes colliders with no body too. The character's own collision_layer and collision_mask filter the rest One of static, kinematic, dynamic, sensors, solids. |
ignore_nodes |
list | [] |
Nodes a move passes through: their colliders, and every collider on their body |
min_slide_angle |
float | 0.5235988 |
The shallowest slope the character slides back down; radians in the file, degrees in the inspector Range 0–90. |
normal_nudge |
float | 0.0001 |
A tiny push along the contact normal that stops the character catching on seams At least 0. |
push_bodies |
bool | true |
Push dynamic bodies the character walks into, rather than passing through them |
push_mass |
float | 0 |
The mass a push is worked out with; 0 takes the body's mass, or the colliders' when there is no body At least 0. |
safe_margin |
float | 0.01 |
A gap kept between the character and everything else, so the solver never has to push it out of a wall At least 0. |
safe_margin_lengths |
enum | absolute |
Whether safe_margin is in world units or a fraction of the character's shape: relative is measured against the height along up_direction One of absolute, relative. |
slide |
bool | true |
Slide along what is in the way instead of stopping dead against it |
step_height |
float | 0.3 |
The tallest step the character climbs without jumping; 0 turns stepping off At least 0. |
step_height_lengths |
enum | absolute |
Whether step_height is in world units or a fraction of the character's shape: relative is measured against the height along up_direction One of absolute, relative. |
step_min_width |
float | 0.2 |
How much clear ground a step needs on top before it may be climbed At least 0. |
step_min_width_lengths |
enum | absolute |
Whether step_min_width is in world units or a fraction of the character's shape: relative is measured against the width across up_direction One of absolute, relative. |
step_on_dynamic |
bool | false |
Climb onto dynamic bodies too, not only static and kinematic ones |
up_direction |
vec2 | [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. Every handle also has get(), set(table), patch(table), has() and remove().
From physics2d:
| method | what it does |
|---|---|
is_on_floor() -> bool |
Whether the last move ended with ground under the character's feet. |
move_character(float, float) -> any |
Move the character by an offset, sliding along walls, climbing steps and staying on the ground: returns #{ x, y, on_floor, sliding, collisions }, each collision carrying the same fields as in 3D. Every solid collider of the character is swept. Call it from fixed_update. |