Skylicht Engine
Loading...
Searching...
No Matches
Skylicht::Physics::CCharacterController Class Reference

A kinematic character controller for handling player movement. More...

#include <CharacterController/CCharacterController.h>

Inheritance diagram for Skylicht::Physics::CCharacterController:
Skylicht::Physics::ICollisionObject Skylicht::CComponentSystem Skylicht::IActivatorObject

Public Member Functions

virtual void initComponent ()
virtual void startComponent ()
virtual void updateComponent ()
virtual void setCollisionGroupAndFilter (int group, int filter)
 Sets the collision group and filter mask.
bool initCharacter (float stepHeight)
 Initializes the character controller in the physics world.
void releaseCharacter ()
 Releases the character controller from the physics world.
core::vector3df getPosition ()
 Gets the current world position of the character.
void setPosition (const core::vector3df &pos)
 Sets the world position of the character.
core::vector3df getRotationEuler ()
 Gets the world rotation as Euler angles.
core::quaternion getRotation ()
 Gets the world rotation as a quaternion.
void setRotation (const core::vector3df &eulerDeg)
 Sets the world rotation using Euler angles.
void setRotation (const core::quaternion &q)
 Sets the world rotation using a quaternion.
void syncTransform ()
 Synchronizes the GameObject's transform with the character's physics transform.
void setWalkDirection (const core::vector3df &walk)
 Sets the direction and speed the character should walk.
bool canJump ()
 Checks if the character is in a state where it can jump.
bool onGround ()
 Checks if the character is currently on the ground.
void setMaxSlope (float slopeRadians)
 Sets the maximum slope the character can walk up.
float getMaxSlope () const
 Gets the maximum slope angle.
void setMaxPenetrationDepth (float d)
 Sets the maximum depth the character can penetrate other objects before collision response.
float getMaxPenetrationDepth () const
 Gets the maximum penetration depth.
void reset ()
 Resets the character controller's state and position in the dynamics world.
void setStepHeight (float h)
 Sets the step height for the character.
float getStepHeight () const
 Gets the current step height.
void setFallSpeed (float fallSpeed)
 Sets the maximum falling speed.
float getFallSpeed () const
 Gets the maximum falling speed.
void setJumpSpeed (float jumpSpeed)
 Sets the initial speed when jumping.
float getJumpSpeed () const
 Gets the initial jump speed.
void setMaxJumpHeight (float maxJumpHeight)
 Sets the maximum height the character can jump.
void jump (const core::vector3df &v)
 Triggers a jump with an optional initial velocity.
void setGravity (const core::vector3df &gravity)
 Sets the custom gravity for this character.
core::vector3df getGravity () const
 Gets the custom gravity of the character.
void applyImpulse (const core::vector3df &v)
 Applies an instantaneous impulse (wraps jump).
void setAngularVelocity (const core::vector3df &velocity)
 Sets the angular velocity of the character.
core::vector3df getAngularVelocity () const
 Gets the angular velocity.
void setLinearVelocity (const core::vector3df &velocity)
 Sets the linear velocity of the character.
core::vector3df getLinearVelocity () const
 Gets the linear velocity.
void setLinearDamping (float d)
 Sets the linear damping coefficient.
float getLinearDamping () const
 Gets the linear damping coefficient.
void setAngularDamping (float d)
 Sets the angular damping coefficient.
float getAngularDamping () const
 Gets the angular damping coefficient.
void setUp (const core::vector3df &up)
 Sets the 'up' direction for the character.
core::vector3df getUp ()
 Gets the 'up' direction.
Public Member Functions inherited from Skylicht::Physics::ICollisionObject
ECollisionType getCollisionType ()
 Gets the collision type.
int getCollisionGroup ()
 Gets the collision group bitmask.
int getCollisionFilter ()
 Gets the collision filter bitmask.
Public Member Functions inherited from Skylicht::CComponentSystem
const char * getName ()
virtual void endUpdate ()
virtual void onEnable (bool b)
virtual void onUpdateCullingLayer (u32 mask)
virtual CObjectSerializablecreateSerializable ()
virtual void loadSerializable (CObjectSerializable *object)
void setEnable (bool b)
bool isEnable ()
CGameObject * getGameObject ()
void setEnableSerializable (bool b)
bool isSerializable ()
void addLinkComponent (CComponentSystem *comp)
void removeAllLink ()
Public Member Functions inherited from Skylicht::IActivatorObject
virtual ~IActivatorObject ()
 Virtual destructor for polymorphic activator objects.

Friends

class CPhysicsEngine

Additional Inherited Members

Public Types inherited from Skylicht::Physics::ICollisionObject
enum  ECollisionType { Unknown , RigidBody , Character }
 Types of collision objects.
Static Public Member Functions inherited from Skylicht::CComponentSystem
static int useComponent (CComponentSystem *used)
Public Attributes inherited from Skylicht::Physics::ICollisionObject
std::function< void(ICollisionObject *, ICollisionObject *, SCollisionContactPoint *, int)> OnCollision
 Callback function triggered when a collision occurs.
Protected Member Functions inherited from Skylicht::CComponentSystem
void setOwner (CGameObject *obj)
Protected Attributes inherited from Skylicht::Physics::ICollisionObject
ECollisionType m_collisionType
int m_group
int m_filter
Protected Attributes inherited from Skylicht::CComponentSystem
CGameObject * m_gameObject
bool m_enable
bool m_serializable
std::vector< CComponentSystem * > m_linkComponent

Detailed Description

A kinematic character controller for handling player movement.

This component provides functionality for walking, jumping, and interacting with the physics world through a ghost object and a kinematic controller (btKinematicCharacterController).

Example: Setting up a player character

CGameObject* playerObj = zone->createEmptyObject();
float radius = 0.5f;
float height = 1.8f;
// 1. Add capsule collider
Physics::CCapsuleCollider* collider = playerObj->addComponent<Physics::CCapsuleCollider>();
collider->setCapsule(radius, height);
// 2. Add and init CharacterController
Physics::CCharacterController* controller = playerObj->addComponent<Physics::CCharacterController>();
controller->initCharacter(0.3f); // stepHeight
// 3. Move character (in update loop)
core::vector3df moveDir(1.0f, 0.0f, 0.0f);
float speed = 5.0f;
float deltaTime = getTimeStep() / 1000.0f;
controller->setWalkDirection(moveDir * speed * deltaTime);
A capsule collision shape.
Definition CCapsuleCollider.h:44
void setCapsule(float radius, float height)
Sets the capsule dimensions.
Definition CCapsuleCollider.h:83
A kinematic character controller for handling player movement.
Definition CCharacterController.h:69
bool initCharacter(float stepHeight)
Initializes the character controller in the physics world.
void setWalkDirection(const core::vector3df &walk)
Sets the direction and speed the character should walk.
float getTimeStep()
Get the current time step in milliseconds, scaled by the time scale.

Member Function Documentation

◆ applyImpulse()

void Skylicht::Physics::CCharacterController::applyImpulse ( const core::vector3df & v)
inline

Applies an instantaneous impulse (wraps jump).

Parameters
vImpulse vector.

◆ canJump()

bool Skylicht::Physics::CCharacterController::canJump ( )

Checks if the character is in a state where it can jump.

Returns
True if character can jump.

◆ getAngularDamping()

float Skylicht::Physics::CCharacterController::getAngularDamping ( ) const

Gets the angular damping coefficient.

Returns
Damping value.

◆ getAngularVelocity()

core::vector3df Skylicht::Physics::CCharacterController::getAngularVelocity ( ) const

Gets the angular velocity.

Returns
Angular velocity vector.

◆ getFallSpeed()

float Skylicht::Physics::CCharacterController::getFallSpeed ( ) const

Gets the maximum falling speed.

Returns
Fall speed value.

◆ getGravity()

core::vector3df Skylicht::Physics::CCharacterController::getGravity ( ) const

Gets the custom gravity of the character.

Returns
Gravity vector.

◆ getJumpSpeed()

float Skylicht::Physics::CCharacterController::getJumpSpeed ( ) const

Gets the initial jump speed.

Returns
Jump speed value.

◆ getLinearDamping()

float Skylicht::Physics::CCharacterController::getLinearDamping ( ) const

Gets the linear damping coefficient.

Returns
Damping value.

◆ getLinearVelocity()

core::vector3df Skylicht::Physics::CCharacterController::getLinearVelocity ( ) const

Gets the linear velocity.

Returns
Linear velocity vector.

◆ getMaxPenetrationDepth()

float Skylicht::Physics::CCharacterController::getMaxPenetrationDepth ( ) const

Gets the maximum penetration depth.

Returns
Penetration depth.

◆ getMaxSlope()

float Skylicht::Physics::CCharacterController::getMaxSlope ( ) const

Gets the maximum slope angle.

Returns
Slope angle in radians.

◆ getPosition()

core::vector3df Skylicht::Physics::CCharacterController::getPosition ( )

Gets the current world position of the character.

Returns
Position vector.

◆ getRotation()

core::quaternion Skylicht::Physics::CCharacterController::getRotation ( )

Gets the world rotation as a quaternion.

Returns
Rotation quaternion.

◆ getRotationEuler()

core::vector3df Skylicht::Physics::CCharacterController::getRotationEuler ( )

Gets the world rotation as Euler angles.

Returns
Euler angles in degrees.

◆ getStepHeight()

float Skylicht::Physics::CCharacterController::getStepHeight ( ) const

Gets the current step height.

Returns
Step height.

◆ getUp()

core::vector3df Skylicht::Physics::CCharacterController::getUp ( )

Gets the 'up' direction.

Returns
Up direction vector.

◆ initCharacter()

bool Skylicht::Physics::CCharacterController::initCharacter ( float stepHeight)

Initializes the character controller in the physics world.

Parameters
stepHeightThe maximum height of steps the character can walk over.
Returns
True if successful, false otherwise.

◆ initComponent()

virtual void Skylicht::Physics::CCharacterController::initComponent ( )
virtual

◆ jump()

void Skylicht::Physics::CCharacterController::jump ( const core::vector3df & v)

Triggers a jump with an optional initial velocity.

Parameters
vInitial jump velocity (optional).

◆ onGround()

bool Skylicht::Physics::CCharacterController::onGround ( )

Checks if the character is currently on the ground.

Returns
True if on ground.

◆ reset()

void Skylicht::Physics::CCharacterController::reset ( )
virtual

Resets the character controller's state and position in the dynamics world.

Reimplemented from Skylicht::CComponentSystem.

◆ setAngularDamping()

void Skylicht::Physics::CCharacterController::setAngularDamping ( float d)

Sets the angular damping coefficient.

Parameters
dDamping value.

◆ setAngularVelocity()

void Skylicht::Physics::CCharacterController::setAngularVelocity ( const core::vector3df & velocity)

Sets the angular velocity of the character.

Parameters
velocityAngular velocity vector.

◆ setCollisionGroupAndFilter()

virtual void Skylicht::Physics::CCharacterController::setCollisionGroupAndFilter ( int group,
int filter )
virtual

Sets the collision group and filter mask.

Parameters
groupBitmask representing the collision group.
filterBitmask representing which groups this object should collide with.

Reimplemented from Skylicht::Physics::ICollisionObject.

◆ setFallSpeed()

void Skylicht::Physics::CCharacterController::setFallSpeed ( float fallSpeed)

Sets the maximum falling speed.

Parameters
fallSpeedFall speed value.

◆ setGravity()

void Skylicht::Physics::CCharacterController::setGravity ( const core::vector3df & gravity)

Sets the custom gravity for this character.

Parameters
gravityGravity vector.

◆ setJumpSpeed()

void Skylicht::Physics::CCharacterController::setJumpSpeed ( float jumpSpeed)

Sets the initial speed when jumping.

Parameters
jumpSpeedJump speed value.

◆ setLinearDamping()

void Skylicht::Physics::CCharacterController::setLinearDamping ( float d)

Sets the linear damping coefficient.

Parameters
dDamping value.

◆ setLinearVelocity()

void Skylicht::Physics::CCharacterController::setLinearVelocity ( const core::vector3df & velocity)

Sets the linear velocity of the character.

Parameters
velocityLinear velocity vector.

◆ setMaxJumpHeight()

void Skylicht::Physics::CCharacterController::setMaxJumpHeight ( float maxJumpHeight)

Sets the maximum height the character can jump.

Parameters
maxJumpHeightMax jump height.

◆ setMaxPenetrationDepth()

void Skylicht::Physics::CCharacterController::setMaxPenetrationDepth ( float d)

Sets the maximum depth the character can penetrate other objects before collision response.

Parameters
dPenetration depth.

◆ setMaxSlope()

void Skylicht::Physics::CCharacterController::setMaxSlope ( float slopeRadians)

Sets the maximum slope the character can walk up.

Parameters
slopeRadiansSlope angle in radians.

◆ setPosition()

void Skylicht::Physics::CCharacterController::setPosition ( const core::vector3df & pos)

Sets the world position of the character.

Parameters
posPosition vector.

◆ setRotation() [1/2]

void Skylicht::Physics::CCharacterController::setRotation ( const core::quaternion & q)

Sets the world rotation using a quaternion.

Parameters
qRotation quaternion.

◆ setRotation() [2/2]

void Skylicht::Physics::CCharacterController::setRotation ( const core::vector3df & eulerDeg)

Sets the world rotation using Euler angles.

Parameters
eulerDegEuler angles in degrees.

◆ setStepHeight()

void Skylicht::Physics::CCharacterController::setStepHeight ( float h)

Sets the step height for the character.

Parameters
hStep height.

◆ setUp()

void Skylicht::Physics::CCharacterController::setUp ( const core::vector3df & up)

Sets the 'up' direction for the character.

Parameters
upUp direction vector.

◆ setWalkDirection()

void Skylicht::Physics::CCharacterController::setWalkDirection ( const core::vector3df & walk)

Sets the direction and speed the character should walk.

Parameters
walkVelocity vector for walking.

◆ startComponent()

virtual void Skylicht::Physics::CCharacterController::startComponent ( )
virtual

Reimplemented from Skylicht::CComponentSystem.

◆ updateComponent()

virtual void Skylicht::Physics::CCharacterController::updateComponent ( )
virtual

The documentation for this class was generated from the following file: