CharacterBody3D class
A character controlled by gameplay rather than forces: a capsule that
walks on ground, slides along walls, climbs steps and slopes, and rides
moving platforms (Jolt's CharacterVirtual). Its entity's position is
its feet.
Each step gameplay sets moveVelocity (and may jump); with useGravity the system adds gravity and the ground's own velocity, as a platformer wants. Without it moveVelocity is the whole velocity (flying, swimming, ladders).
Constructors
- CharacterBody3D({double radius = 0.3, double height = 1.8, double maxSlopeAngle = 0.8726646259971648, double stepHeight = 0.4, double stickToFloor = 0.5, double mass = 70.0, double pushStrength = 100.0, double gravityScale = 1.0, bool useGravity = true, int layer = 0, bool detectable = true})
- A character 1.8 m tall and 0.3 m in radius, by default.
Properties
- character ↔ int
-
The physics engine's character, or 0 while it has none.
getter/setter pair
- componentType → Type
-
Type identifier for this component
no setterinherited
- detectable ↔ bool
-
Whether sensors detect it and rays hit it.
getter/setter pair
- gravityScale ↔ double
-
Gravity on it, times this, with useGravity.
getter/setter pair
- groundEntity ↔ Entity?
-
The entity it stands on, or null.
getter/setter pair
- groundNormal → Vector3
-
The ground's normal after the last step.
final
- groundState ↔ GroundState3D
-
What it stands on after the last step.
getter/setter pair
- groundVelocity → Vector3
-
The ground's velocity after the last step (a moving platform's).
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- height ↔ double
-
Its whole height, feet to the top of its head.
getter/setter pair
- isGrounded → bool
-
Whether it stands on walkable ground.
no setter
- layer ↔ int
-
Its collision layer, 0–15.
getter/setter pair
- mass ↔ double
-
Its mass (kg): how hard it pushes bodies it walks into.
getter/setter pair
- maxSlopeAngle ↔ double
-
Steepest slope it can walk up, radians (50° by default).
getter/setter pair
- moveVelocity → Vector3
-
The velocity gameplay wants it to move at; kept until changed.
final
- pendingJump ↔ double?
-
A jump speed waiting for the next step, or null.
getter/setter pair
- pushStrength ↔ double
-
The most force it pushes with (N).
getter/setter pair
- radius ↔ double
-
Radius of its capsule.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stepHeight ↔ double
-
Tallest step it climbs; 0 climbs none.
getter/setter pair
- stickToFloor ↔ double
-
How far down it keeps to the floor going down slopes and steps; 0
leaves the ground at every edge.
getter/setter pair
- useGravity ↔ bool
-
Whether the system adds gravity and the ground's velocity.
getter/setter pair
- velocity → Vector3
-
Its velocity after the last step.
final
Methods
-
jump(
double speed) → void -
Jumps at
speedm/s at the next step, if it is on the ground then (with useGravity). -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onAttach(
EntityId entityId) → void -
Called when this component is added to an entity.
inherited
-
onDetach(
EntityId entityId) → void -
Called when this component is removed from an entity.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited