reckfellENGINE

CharacterBody3D

A code-controlled 3D character body.

On this page
class CharacterBody3DReckfellSharpInherits PhysicsBody3D

CharacterBody3D moves through MoveAndSlide or MoveAndCollide. The script defines acceleration, input and jump rules; the type alone does not add controls or gravity.

Set Velocity in units/s before MoveAndSlide without multiplying by delta again. MoveAndCollide accepts displacement for the call. IsOnFloor/IsOnWall and slide contacts describe the last MoveAndSlide, not persistent proximity. After teleporting, do not authorize an action using old floor state. Grounded/Floating, UpDirection, snap and maximum-angle settings serve separate roles.

Working examples.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

CharacterBody3DConstructor
# CharacterBody3D
C#
public CharacterBody3D();

Properties15

FloorBlockOnWallProperty
# FloorBlockOnWall
C#
public bool FloorBlockOnWall { get; set; }

If true, the body will be able to move on the floor only. This option avoids to be able to walk on walls, it will however allow to slide down along them.

FloorConstantSpeedProperty
# FloorConstantSpeed
C#
public bool FloorConstantSpeed { get; set; }

If false (by default), the body will move faster on downward slopes and slower on upward slopes. If true, the body will always move at the same speed on the ground no matter the slope. Note that you need to use CharacterBody3D.FloorSnapLength to stick along a downward slope at constant speed.

FloorMaxAngleProperty
# FloorMaxAngle
C#
public float FloorMaxAngle { get; set; }

The floor/ceiling classification angle relative to UpDirection, in radians. Use Mathf.DegToRad(45) for 45 degrees.

FloorSnapLengthProperty
# FloorSnapLength
C#
public float FloorSnapLength { get; set; }

Sets a snapping distance. When set to a value different from 0.0, the body is kept attached to slopes when calling CharacterBody3D.MoveAndSlide. The snapping vector is determined by the given distance along the opposite direction of the CharacterBody3D.UpDirection. As long as the snapping vector is in contact with the ground and the body moves against CharacterBody3D.UpDirection, the body will remain attached to the surface. Snapping is not applied if the body moves along CharacterBody3D.UpDirection, meaning it contains vertical rising velocity, so it will be able to detach from the ground when jumping or when the body is pushed up by something. If you want to apply a snap without taking into account the velocity, use CharacterBody3D.ApplyFloorSnap.

FloorStopOnSlopeProperty
# FloorStopOnSlope
C#
public bool FloorStopOnSlope { get; set; }

If true, the body will not slide on slopes when calling CharacterBody3D.MoveAndSlide when the body is standing still. If false, the body will slide on floor's slopes when CharacterBody3D.Velocity applies a downward force.

MaxSlidesProperty
# MaxSlides
C#
public int MaxSlides { get; set; }

Maximum number of times the body can change direction before it stops when calling CharacterBody3D.MoveAndSlide. Must be greater than zero.

MotionModeProperty
# MotionMode
C#
public CharacterBody3D.MotionModeEnum MotionMode { get; set; }

Sets the motion mode which defines the behavior of CharacterBody3D.MoveAndSlide.

PlatformFloorLayersProperty
# PlatformFloorLayers
C#
public uint PlatformFloorLayers { get; set; }

Collision layers that will be included for detecting floor bodies that will act as moving platforms to be followed by the CharacterBody3D. By default, all floor bodies are detected and propagate their velocity.

PlatformOnLeaveProperty
# PlatformOnLeave
C#
public CharacterBody3D.PlatformOnLeaveEnum PlatformOnLeave { get; set; }

Sets the behavior to apply when you leave a moving platform. By default, to be physically accurate, when you leave the last platform velocity is applied.

PlatformWallLayersProperty
# PlatformWallLayers
C#
public uint PlatformWallLayers { get; set; }

Collision layers that will be included for detecting wall bodies that will act as moving platforms to be followed by the CharacterBody3D. By default, all wall bodies are ignored.

SafeMarginProperty
# SafeMargin
C#
public float SafeMargin { get; set; }

Extra margin used for collision recovery when calling CharacterBody3D.MoveAndSlide. If the body is at least this close to another body, it will consider them to be colliding and will be pushed away before performing the actual motion. A higher value means it's more flexible for detecting collision, which helps with consistently detecting walls and floors. A lower value forces the collision algorithm to use more exact detection, so it can be used in cases that specifically require precision, e.g at very low scale to avoid visible jittering, or for stability with a stack of character bodies.

SlideOnCeilingProperty
# SlideOnCeiling
C#
public bool SlideOnCeiling { get; set; }

If true, during a jump against the ceiling, the body will slide, if false it will be stopped and will fall vertically.

UpDirectionProperty
# UpDirection
C#
public Vector3 UpDirection { get; set; }

Vector pointing upwards, used to determine what is a wall and what is a floor (or a ceiling) when calling CharacterBody3D.MoveAndSlide. Defaults to Vector3.Up. As the vector will be normalized it can't be equal to Vector3.Zero, if you want all collisions to be reported as walls, consider using CharacterBody3D.MotionModeEnum.Floating as CharacterBody3D.MotionMode.

VelocityProperty
# Velocity
C#
public Vector3 Velocity { get; set; }

Body velocity in units per second for MoveAndSlide. Do not multiply by delta before calling: movement integrates the step internally. MoveAndSlide may modify velocity during collisions.

WallMinSlideAngleProperty
# WallMinSlideAngle
C#
public float WallMinSlideAngle { get; set; }

Minimum angle (in radians) where the body is allowed to slide when it encounters a wall. The default value equals 15 degrees. When CharacterBody3D.MotionMode is CharacterBody3D.MotionModeEnum.Grounded, it only affects movement if CharacterBody3D.FloorBlockOnWall is true.

Methods49

ApplyFloorSnapvoid
# ApplyFloorSnap
C#
public void ApplyFloorSnap();

Allows to manually apply a snap to the floor regardless of the body's velocity. This function does nothing when CharacterBody3D.IsOnFloor returns true.

GetFloorAnglefloat
# GetFloorAngle
C#
public float GetFloorAngle(Vector3? upDirection = default);

Returns the floor's collision angle at the last collision point according to CharacterBody3D.UpDirection, which is Vector3.Up by default. This value is always positive and only valid after calling CharacterBody3D.MoveAndSlide and when CharacterBody3D.IsOnFloor returns true.

Parameters
NameTypeDefault
upDirectionVector3?default
upDirection

If the parameter is null, then the default value is new Vector3(0.0f, 1.0f, 0.0f).

Returns float
GetFloorMaxAnglefloat
# GetFloorMaxAngle
C#
public float GetFloorMaxAngle();
Returns float
GetFloorNormalVector3
# GetFloorNormal
C#
public Vector3 GetFloorNormal();

Returns the collision normal of the floor at the last collision point. Only valid after calling CharacterBody3D.MoveAndSlide and when CharacterBody3D.IsOnFloor returns true. Warning: The collision normal is not always the same as the surface normal.

Returns Vector3
GetFloorSnapLengthfloat
# GetFloorSnapLength
C#
public float GetFloorSnapLength();
Returns float
GetLastMotionVector3
# GetLastMotion
C#
public Vector3 GetLastMotion();

Returns the last motion applied to the CharacterBody3D during the last call to CharacterBody3D.MoveAndSlide. The movement can be split into multiple motions when sliding occurs, and this method return the last one, which is useful to retrieve the current direction of the movement.

Returns Vector3
GetLastSlideCollisionKinematicCollision3D
# GetLastSlideCollision
C#
public KinematicCollision3D GetLastSlideCollision();

Returns a KinematicCollision3D if a collision occurred. The returned value contains information about the latest collision that occurred during the last call to CharacterBody3D.MoveAndSlide. Returns null if no collision occurred. See also CharacterBody3D.GetSlideCollision.

Returns KinematicCollision3D
GetMaxSlidesint
# GetMaxSlides
C#
public int GetMaxSlides();
Returns int
GetMotionModeCharacterBody3D.MotionModeEnum
# GetMotionMode
C#
public CharacterBody3D.MotionModeEnum GetMotionMode();
Returns CharacterBody3D.MotionModeEnum
GetPlatformAngularVelocityVector3
# GetPlatformAngularVelocity
C#
public Vector3 GetPlatformAngularVelocity();

Returns the angular velocity of the platform at the last collision point. Only valid after calling CharacterBody3D.MoveAndSlide.

Returns Vector3
GetPlatformFloorLayersuint
# GetPlatformFloorLayers
C#
public uint GetPlatformFloorLayers();
Returns uint
GetPlatformOnLeaveCharacterBody3D.PlatformOnLeaveEnum
# GetPlatformOnLeave
C#
public CharacterBody3D.PlatformOnLeaveEnum GetPlatformOnLeave();
Returns CharacterBody3D.PlatformOnLeaveEnum
GetPlatformVelocityVector3
# GetPlatformVelocity
C#
public Vector3 GetPlatformVelocity();

Returns the linear velocity of the platform at the last collision point. Only valid after calling CharacterBody3D.MoveAndSlide.

Returns Vector3
GetPlatformWallLayersuint
# GetPlatformWallLayers
C#
public uint GetPlatformWallLayers();
Returns uint
GetPositionDeltaVector3
# GetPositionDelta
C#
public Vector3 GetPositionDelta();

Returns the travel (position delta) that occurred during the last call to CharacterBody3D.MoveAndSlide.

Returns Vector3
GetRealVelocityVector3
# GetRealVelocity
C#
public Vector3 GetRealVelocity();

Returns the current real velocity since the last call to CharacterBody3D.MoveAndSlide. For example, when you climb a slope, you will move diagonally even though the velocity is horizontal. This method returns the diagonal movement, as opposed to CharacterBody3D.Velocity which returns the requested velocity.

Returns Vector3
GetSafeMarginfloat
# GetSafeMargin
C#
public float GetSafeMargin();
Returns float
GetSlideCollisionKinematicCollision3D
# GetSlideCollision
C#
public KinematicCollision3D GetSlideCollision(int slideIdx);

Returns a KinematicCollision3D, which contains information about a collision that occurred during the last call to CharacterBody3D.MoveAndSlide. Since the body can collide several times in a single call to CharacterBody3D.MoveAndSlide, you must specify the index of the collision in the range 0 to (CharacterBody3D.GetSlideCollisionCount - 1). See also CharacterBody3D.GetLastSlideCollision.

Parameters
NameTypeDefault
slideIdxint—
Returns KinematicCollision3D
GetSlideCollisionCountint
# GetSlideCollisionCount
C#
public int GetSlideCollisionCount();

The number of slide contacts from the last MoveAndSlide. Not a count of every neighboring body; read MoveAndCollide data from its returned object.

Returns int
GetUpDirectionVector3
# GetUpDirection
C#
public Vector3 GetUpDirection();
Returns Vector3
GetVelocityVector3
# GetVelocity
C#
public Vector3 GetVelocity();
Returns Vector3
GetWallMinSlideAnglefloat
# GetWallMinSlideAngle
C#
public float GetWallMinSlideAngle();
Returns float
GetWallNormalVector3
# GetWallNormal
C#
public Vector3 GetWallNormal();

Returns the collision normal of the wall at the last collision point. Only valid after calling CharacterBody3D.MoveAndSlide and when CharacterBody3D.IsOnWall returns true. Warning: The collision normal is not always the same as the surface normal.

Returns Vector3
IsFloorBlockOnWallEnabledbool
# IsFloorBlockOnWallEnabled
C#
public bool IsFloorBlockOnWallEnabled();
Returns bool
IsFloorConstantSpeedEnabledbool
# IsFloorConstantSpeedEnabled
C#
public bool IsFloorConstantSpeedEnabled();
Returns bool
IsFloorStopOnSlopeEnabledbool
# IsFloorStopOnSlopeEnabled
C#
public bool IsFloorStopOnSlopeEnabled();
Returns bool
IsOnCeilingbool
# IsOnCeiling
C#
public bool IsOnCeiling();

Returns true if the body collided with the ceiling on the last call of CharacterBody3D.MoveAndSlide. Otherwise, returns false. The CharacterBody3D.UpDirection and CharacterBody3D.FloorMaxAngle are used to determine whether a surface is "ceiling" or not.

Returns bool
IsOnCeilingOnlybool
# IsOnCeilingOnly
C#
public bool IsOnCeilingOnly();

Returns true if the body collided only with the ceiling on the last call of CharacterBody3D.MoveAndSlide. Otherwise, returns false. The CharacterBody3D.UpDirection and CharacterBody3D.FloorMaxAngle are used to determine whether a surface is "ceiling" or not.

Returns bool
IsOnFloorbool
# IsOnFloor
C#
public bool IsOnFloor();

Reads floor-contact state produced by movement processing. Use after a physics step, rather than as a NavigationMesh-presence test.

Returns bool

true for a detected floor contact. A navigation mesh without a physics surface does not create that contact.

IsOnFloorOnlybool
# IsOnFloorOnly
C#
public bool IsOnFloorOnly();

Returns true if the body collided only with the floor on the last call of CharacterBody3D.MoveAndSlide. Otherwise, returns false. The CharacterBody3D.UpDirection and CharacterBody3D.FloorMaxAngle are used to determine whether a surface is "floor" or not.

Returns bool
IsOnWallbool
# IsOnWall
C#
public bool IsOnWall();

Returns true if the body collided with a wall on the last call of CharacterBody3D.MoveAndSlide. Otherwise, returns false. The CharacterBody3D.UpDirection and CharacterBody3D.FloorMaxAngle are used to determine whether a surface is "wall" or not.

Returns bool
IsOnWallOnlybool
# IsOnWallOnly
C#
public bool IsOnWallOnly();

Returns true if the body collided only with a wall on the last call of CharacterBody3D.MoveAndSlide. Otherwise, returns false. The CharacterBody3D.UpDirection and CharacterBody3D.FloorMaxAngle are used to determine whether a surface is "wall" or not.

Returns bool
IsSlideOnCeilingEnabledbool
# IsSlideOnCeilingEnabled
C#
public bool IsSlideOnCeilingEnabled();
Returns bool
MoveAndSlidebool
# MoveAndSlide
C#
public bool MoveAndSlide();

Moves the body using Velocity and collision response. Uses the engine time step; your code supplies velocity and gravity acceleration. Does not search navigation paths or establish goal arrival.

Returns bool

true when movement registered collisions; not an indication of successful navigation completion.

SetFloorBlockOnWallEnabledvoid
# SetFloorBlockOnWallEnabled
C#
public void SetFloorBlockOnWallEnabled(bool enabled);
Parameters
NameTypeDefault
enabledbool—
SetFloorConstantSpeedEnabledvoid
# SetFloorConstantSpeedEnabled
C#
public void SetFloorConstantSpeedEnabled(bool enabled);
Parameters
NameTypeDefault
enabledbool—
SetFloorMaxAnglevoid
# SetFloorMaxAngle
C#
public void SetFloorMaxAngle(float radians);
Parameters
NameTypeDefault
radiansfloat—
SetFloorSnapLengthvoid
# SetFloorSnapLength
C#
public void SetFloorSnapLength(float floorSnapLength);
Parameters
NameTypeDefault
floorSnapLengthfloat—
SetFloorStopOnSlopeEnabledvoid
# SetFloorStopOnSlopeEnabled
C#
public void SetFloorStopOnSlopeEnabled(bool enabled);
Parameters
NameTypeDefault
enabledbool—
SetMaxSlidesvoid
# SetMaxSlides
C#
public void SetMaxSlides(int maxSlides);
Parameters
NameTypeDefault
maxSlidesint—
SetMotionModevoid
# SetMotionMode
C#
public void SetMotionMode(CharacterBody3D.MotionModeEnum mode);
Parameters
NameTypeDefault
modeCharacterBody3D.MotionModeEnum—
SetPlatformFloorLayersvoid
# SetPlatformFloorLayers
C#
public void SetPlatformFloorLayers(uint excludeLayer);
Parameters
NameTypeDefault
excludeLayeruint—
SetPlatformOnLeavevoid
# SetPlatformOnLeave
C#
public void SetPlatformOnLeave(CharacterBody3D.PlatformOnLeaveEnum onLeaveApplyVelocity);
Parameters
NameTypeDefault
onLeaveApplyVelocityCharacterBody3D.PlatformOnLeaveEnum—
SetPlatformWallLayersvoid
# SetPlatformWallLayers
C#
public void SetPlatformWallLayers(uint excludeLayer);
Parameters
NameTypeDefault
excludeLayeruint—
SetSafeMarginvoid
# SetSafeMargin
C#
public void SetSafeMargin(float margin);
Parameters
NameTypeDefault
marginfloat—
SetSlideOnCeilingEnabledvoid
# SetSlideOnCeilingEnabled
C#
public void SetSlideOnCeilingEnabled(bool enabled);
Parameters
NameTypeDefault
enabledbool—
SetUpDirectionvoid
# SetUpDirection
C#
public void SetUpDirection(Vector3 upDirection);
Parameters
NameTypeDefault
upDirectionVector3—
SetVelocityvoid
# SetVelocity
C#
public void SetVelocity(Vector3 velocity);
Parameters
NameTypeDefault
velocityVector3—
SetWallMinSlideAnglevoid
# SetWallMinSlideAngle
C#
public void SetWallMinSlideAngle(float radians);
Parameters
NameTypeDefault
radiansfloat—

CharacterBody3D.MotionModeEnum

ValueDescription
Floating = 1

Apply when there is no notion of floor or ceiling. All collisions will be reported as on_wall. In this mode, when you slide, the speed will always be constant. This mode is suitable for games without ground like space games.

Grounded = 0

Apply when notions of walls, ceiling and floor are relevant. In this mode the body motion will react to slopes (acceleration/slowdown). This mode is suitable for grounded games like platformers.

CharacterBody3D.PlatformOnLeaveEnum

ValueDescription
AddUpwardVelocity = 1

Add the last platform velocity to the CharacterBody3D.Velocity when you leave a moving platform, but any downward motion is ignored. It's useful to keep full jump height even when the platform is moving down.

AddVelocity = 0

Add the last platform velocity to the CharacterBody3D.Velocity when you leave a moving platform.

DoNothing = 2

Do nothing when leaving a platform.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.