Skip to main content

CharacterBody2D

Inherits: PhysicsBody2D < CollisionObject2D < Node2D < CanvasItem < Node < Object

Description

A 2D physics body specialized for characters moved by script. They are not affected by physics but affect other physics bodies in their path.

Properties

Vector2
default:"Vector2(0, 0)"
Current velocity vector in pixels per second, used and modified during calls to move_and_slide.
MotionMode
default:"MOTION_MODE_GROUNDED"
Sets the motion mode which defines the behavior of move_and_slide.
Vector2
default:"Vector2(0, -1)"
Vector pointing upwards, used to determine what is a wall and what is a floor.
float
default:"0.785398"
Maximum angle (in radians) where a slope is still considered a floor (45 degrees by default).
float
default:"1.0"
Sets a snapping distance. When set to a value different from 0.0, the body is kept attached to slopes.

Methods

move_and_slide

Moves the body based on velocity. Returns true if the body collided.

is_on_floor

Returns true if the body collided with the floor on the last call of move_and_slide.

is_on_wall

Returns true if the body collided with a wall on the last call of move_and_slide.

is_on_ceiling

Returns true if the body collided with the ceiling on the last call of move_and_slide.

get_floor_normal

Returns the collision normal of the floor at the last collision point.

Example Usage