Class CharacterController
Physical objects that allows to easily do player movement constrained by collisions without having to deal with a rigidbody.
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Physics/Colliders/CharacterController.h
Syntax
public class CharacterController : public Collider, public IPhysicsActor
Methods
AddMovement(const Vector3& translation, const Quaternion& rotation)
Moves the actor (also can rotate it) in world space.
Declaration
public virtual void AddMovement(const Vector3& translation, const Quaternion& rotation) override
Parameters
Vector3
translation
The translation vector. |
Quaternion
rotation
The rotation quaternion. |
Overrides
BeginPlay(SceneBeginData* data)
Called when adding object to the game.
Declaration
protected virtual void BeginPlay(SceneBeginData* data) override
Parameters
SceneBeginData
data
The initialization data (e.g. used to collect joints to link after begin). |
Overrides
CanAttach(RigidBody* rigidBody)
Determines whether this collider can be attached the specified rigid body.
Declaration
public virtual bool CanAttach(RigidBody* rigidBody) const override
Parameters
RigidBody
rigidBody
The rigid body. |
Returns
bool
|
Overrides
CreateController()
Creates the physics actor.
Declaration
protected void CreateController()
CreateShape()
Creates the collider shape.
Declaration
public virtual void CreateShape() override
Overrides
DeleteController()
Deletes the physics actor.
Declaration
protected void DeleteController()
DrawPhysicsDebug(RenderView& view)
Declaration
protected virtual void DrawPhysicsDebug(RenderView& view) override
Parameters
RenderView
view
|
Overrides
EndPlay()
Called when removing object from the game.
Declaration
protected virtual void EndPlay() override
Overrides
GetAttachedRigidBody()
Gets the attached rigid body.
Declaration
public virtual RigidBody* GetAttachedRigidBody() const override
Returns
RigidBody
The rigid body or null. |
Overrides
GetAutoGravity()
Gets the automatic gravity force applying mode. Can be toggled off if gameplay controls character movement velocity including gravity, or toggled on if gravity should be applied together with root motion from animation movement.
Declaration
public bool GetAutoGravity() const
Returns
bool
|
GetFlags()
Gets the current collision flags. Tells which parts of the character capsule collided with the environment during the last move call. It can be used to trigger various character animations.
Declaration
public CollisionFlags GetFlags() const
Returns
CollisionFlags
|
GetGeometry(CollisionShape& collision)
Gets the collider shape geometry.
Declaration
protected virtual void GetGeometry(CollisionShape& collision) override
Parameters
CollisionShape
collision
The output collision shape. |
Overrides
GetHeight()
Gets the height of the capsule, measured in the object's local space. The capsule height will be scaled by the actor's world scale.
Declaration
public float GetHeight() const
Returns
float
|
GetMinMoveDistance()
Gets the minimum move distance of the character controller. The minimum traveled distance to consider. If traveled distance is smaller, the character doesn't move. This is used to stop the recursive motion algorithm when remaining distance to travel is small.
Declaration
public float GetMinMoveDistance() const
Returns
float
|
GetNonWalkableMode()
Gets the non-walkable mode for the character controller.
Declaration
public NonWalkableModes GetNonWalkableMode() const
Returns
NonWalkableModes
|
GetPhysicsActor()
Gets the native physics backend object.
Declaration
public virtual void* GetPhysicsActor() const override
Returns
void
|
Overrides
GetRadius()
Gets the radius of the sphere, measured in the object's local space. The sphere radius will be scaled by the actor's world scale.
Declaration
public float GetRadius() const
Returns
float
|
GetSlopeLimit()
Gets the slope limit (in degrees). Limits the collider to only climb slopes that are less steep (in degrees) than the indicated value.
Declaration
public float GetSlopeLimit() const
Returns
float
|
GetStepOffset()
Gets the step height. The character will step up a stair only if it is closer to the ground than the indicated value. This should not be greater than the Character Controller’s height or it will generate an error.
Declaration
public float GetStepOffset() const
Returns
float
|
GetUpDirection()
Gets the character up vector.
Declaration
public Vector3 GetUpDirection() const
Returns
Vector3
|
GetVelocity()
Gets the linear velocity of the Character Controller. This allows tracking how fast the character is actually moving, for instance when it is stuck at a wall this value will be the near zero vector.
Declaration
public Vector3 GetVelocity() const
Returns
Vector3
|
IsGrounded()
Gets a value indicating whether this character was grounded during last move call grounded.
Declaration
public bool IsGrounded() const
Returns
bool
|
Move(const Vector3& displacement)
Moves the character using a 'collide-and-slide' algorithm. Attempts to move the controller by the given displacement vector, the motion will only be constrained by collisions. It will slide along colliders. Result collision flags is the summary of collisions that occurred during the Move. This function does not apply any gravity.
Declaration
public CollisionFlags Move(const Vector3& displacement)
Parameters
Vector3
displacement
The displacement vector (in world units). |
Returns
CollisionFlags
The collision flags. It can be used to trigger various character animations. |
OnActiveInTreeChanged()
Called when actor active in tree state gets changed.
Declaration
protected virtual void OnActiveInTreeChanged() override
Overrides
OnActiveTransformChanged()
Called when actor's active transformation gets changed after the physics simulation step during.
This event is called internally by the Physics service and should not be used by the others.
Declaration
public virtual void OnActiveTransformChanged() override
Overrides
OnDebugDrawSelected()
Draws debug shapes for the selected actor and all child scripts.
Declaration
public virtual void OnDebugDrawSelected() override
Overrides
OnDisable()
Called when actor gets removed from game systems. Occurs on EndPlay event or when actor gets inactivated in hierarchy. Use this event to unregister object from other game system (eg. audio).
Declaration
protected virtual void OnDisable() override
Overrides
OnEnable()
Called when actor gets added to game systems. Occurs on BeginPlay event or when actor gets activated in hierarchy. Use this event to register object to other game system (eg. audio).
Declaration
protected virtual void OnEnable() override
Overrides
OnParentChanged()
Called when actor parent gets changed.
Declaration
protected virtual void OnParentChanged() override
Overrides
OnPhysicsSceneChanged(PhysicsScene* previous)
Declaration
protected virtual void OnPhysicsSceneChanged(PhysicsScene* previous) override
Parameters
PhysicsScene
previous
|
Overrides
OnTransformChanged()
Called when actor transform gets changed.
Declaration
protected virtual void OnTransformChanged() override
Overrides
SetAutoGravity(bool value)
Sets the automatic gravity force applying mode. Can be toggled off if gameplay controls character movement velocity including gravity, or toggled on if gravity should be applied together with root motion from animation movement.
Declaration
public void SetAutoGravity(bool value)
Parameters
bool
value
|
SetHeight(float value)
Sets the height of the capsule, measured in the object's local space. The capsule height will be scaled by the actor's world scale.
Declaration
public void SetHeight(float value)
Parameters
float
value
|
SetMinMoveDistance(float value)
Sets the minimum move distance of the character controller.The minimum traveled distance to consider. If traveled distance is smaller, the character doesn't move. This is used to stop the recursive motion algorithm when remaining distance to travel is small.
Declaration
public void SetMinMoveDistance(float value)
Parameters
float
value
|
SetNonWalkableMode(NonWalkableModes value)
Sets the non-walkable mode for the character controller.
Declaration
public void SetNonWalkableMode(NonWalkableModes value)
Parameters
NonWalkableModes
value
|
SetRadius(float value)
Sets the radius of the sphere, measured in the object's local space. The sphere radius will be scaled by the actor's world scale.
Declaration
public void SetRadius(float value)
Parameters
float
value
|
SetSlopeLimit(float value)
Sets the slope limit (in degrees). Limits the collider to only climb slopes that are less steep (in degrees) than the indicated value.
Declaration
public void SetSlopeLimit(float value)
Parameters
float
value
|
SetStepOffset(float value)
Sets the step height. The character will step up a stair only if it is closer to the ground than the indicated value. This should not be greater than the Character Controller’s height or it will generate an error.
Declaration
public void SetStepOffset(float value)
Parameters
float
value
|
SetUpDirection(const Vector3& up)
Sets the character up vector.
Declaration
public void SetUpDirection(const Vector3& up)
Parameters
Vector3
up
|
SimpleMove(const Vector3& speed)
Moves the character with the given speed. Gravity is automatically applied. It will slide along colliders. Result collision flags is the summary of collisions that occurred during the Move.
Declaration
public CollisionFlags SimpleMove(const Vector3& speed)
Parameters
Vector3
speed
The movement speed (in units/s). |
Returns
CollisionFlags
The collision flags. It can be used to trigger various character animations. |
UpdateBounds()
Updates the bounding box of the shape.
Declaration
public virtual void UpdateBounds() override
Overrides
UpdateGeometry()
Updates the shape geometry.
Declaration
protected virtual void UpdateGeometry() override
Overrides
UpdateSize()
Updates the character height and radius.
Declaration
protected void UpdateSize() const