Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
Character Class Reference

#include <Character.h>

Inheritance diagram for Character:
CharacterBase RefTarget< CharacterBase > NonCopyable

Public Member Functions

JPH_OVERRIDE_NEW_DELETE Character (const CharacterSettings *inSettings, RVec3Arg inPosition, QuatArg inRotation, uint64 inUserData, PhysicsSystem *inSystem)
 
virtual ~Character () override
 Destructor.
 
void AddToPhysicsSystem (EActivation inActivationMode=EActivation::Activate, bool inLockBodies=true)
 Add bodies and constraints to the system and optionally activate the bodies.
 
void RemoveFromPhysicsSystem (bool inLockBodies=true)
 Remove bodies and constraints from the system.
 
void Activate (bool inLockBodies=true)
 Wake up the character.
 
void PostSimulation (float inMaxSeparationDistance, bool inLockBodies=true)
 
void SetLinearAndAngularVelocity (Vec3Arg inLinearVelocity, Vec3Arg inAngularVelocity, bool inLockBodies=true)
 Control the velocity of the character.
 
Vec3 GetLinearVelocity (bool inLockBodies=true) const
 Get the linear velocity of the character (m / s)
 
void SetLinearVelocity (Vec3Arg inLinearVelocity, bool inLockBodies=true)
 Set the linear velocity of the character (m / s)
 
void AddLinearVelocity (Vec3Arg inLinearVelocity, bool inLockBodies=true)
 Add world space linear velocity to current velocity (m / s)
 
void AddImpulse (Vec3Arg inImpulse, bool inLockBodies=true)
 Add impulse to the center of mass of the character.
 
BodyID GetBodyID () const
 Get the body associated with this character.
 
void GetPositionAndRotation (RVec3 &outPosition, Quat &outRotation, bool inLockBodies=true) const
 Get position / rotation of the body.
 
void SetPositionAndRotation (RVec3Arg inPosition, QuatArg inRotation, EActivation inActivationMode=EActivation::Activate, bool inLockBodies=true) const
 Set the position / rotation of the body, optionally activating it.
 
RVec3 GetPosition (bool inLockBodies=true) const
 Get the position of the character.
 
void SetPosition (RVec3Arg inPosition, EActivation inActivationMode=EActivation::Activate, bool inLockBodies=true)
 Set the position of the character, optionally activating it.
 
Quat GetRotation (bool inLockBodies=true) const
 Get the rotation of the character.
 
void SetRotation (QuatArg inRotation, EActivation inActivationMode=EActivation::Activate, bool inLockBodies=true)
 Set the rotation of the character, optionally activating it.
 
RVec3 GetCenterOfMassPosition (bool inLockBodies=true) const
 Position of the center of mass of the underlying rigid body.
 
RMat44 GetWorldTransform (bool inLockBodies=true) const
 Calculate the world transform of the character.
 
ObjectLayer GetLayer () const
 Get the layer of the character.
 
void SetLayer (ObjectLayer inLayer, bool inLockBodies=true)
 Update the layer of the character.
 
bool SetShape (const Shape *inShape, float inMaxPenetrationDepth, bool inLockBodies=true)
 
TransformedShape GetTransformedShape (bool inLockBodies=true) const
 Get the transformed shape that represents the volume of the character, can be used for collision checks.
 
void CheckCollision (RVec3Arg inPosition, QuatArg inRotation, Vec3Arg inMovementDirection, float inMaxSeparationDistance, const Shape *inShape, RVec3Arg inBaseOffset, CollideShapeCollector &ioCollector, bool inLockBodies=true) const
 Get all contacts for the character at a particular location.
 
- Public Member Functions inherited from CharacterBase
JPH_OVERRIDE_NEW_DELETE CharacterBase (const CharacterBaseSettings *inSettings, PhysicsSystem *inSystem)
 Constructor.
 
virtual ~CharacterBase ()=default
 Destructor.
 
void SetMaxSlopeAngle (float inMaxSlopeAngle)
 Set the maximum angle of slope that character can still walk on (radians)
 
float GetCosMaxSlopeAngle () const
 
void SetUp (Vec3Arg inUp)
 Set the up vector for the character.
 
Vec3 GetUp () const
 
bool IsSlopeTooSteep (Vec3Arg inNormal) const
 Check if the normal of the ground surface is too steep to walk on.
 
const ShapeGetShape () const
 Get the current shape that the character is using.
 
EGroundState GetGroundState () const
 Current ground state.
 
bool IsSupported () const
 Returns true if the player is supported by normal or steep ground.
 
RVec3 GetGroundPosition () const
 Get the contact point with the ground.
 
Vec3 GetGroundNormal () const
 Get the contact normal with the ground.
 
Vec3 GetGroundVelocity () const
 Velocity in world space of ground.
 
const PhysicsMaterialGetGroundMaterial () const
 Material that the character is standing on.
 
BodyID GetGroundBodyID () const
 BodyID of the object the character is standing on. Note may have been removed!
 
SubShapeID GetGroundSubShapeID () const
 Sub part of the body that we're standing on.
 
uint64 GetGroundUserData () const
 User data value of the body that we're standing on.
 
virtual void SaveState (StateRecorder &inStream) const
 
virtual void RestoreState (StateRecorder &inStream)
 
- Public Member Functions inherited from RefTarget< CharacterBase >
 RefTarget ()=default
 Constructor.
 
 RefTarget (const RefTarget &)
 
 ~RefTarget ()
 assert no one is referencing us
 
void SetEmbedded () const
 
RefTargetoperator= (const RefTarget &)
 Assignment operator.
 
uint32 GetRefCount () const
 Get current refcount of this object.
 
void AddRef () const
 Add or release a reference to this object.
 
void Release () const
 
- Public Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 

Additional Inherited Members

- Public Types inherited from CharacterBase
enum class  EGroundState { OnGround , OnSteepGround , NotSupported , InAir }
 
- Static Public Member Functions inherited from CharacterBase
static const char * sToString (EGroundState inState)
 Debug function to convert enum values to string.
 
- Static Public Member Functions inherited from RefTarget< CharacterBase >
static int sInternalGetRefCountOffset ()
 INTERNAL HELPER FUNCTION USED BY SERIALIZATION.
 
- Protected Attributes inherited from CharacterBase
PhysicsSystemmSystem
 
RefConst< ShapemShape
 
Vec3 mUp
 
Plane mSupportingVolume
 
float mCosMaxSlopeAngle
 
EGroundState mGroundState = EGroundState::InAir
 
BodyID mGroundBodyID
 
SubShapeID mGroundBodySubShapeID
 
RVec3 mGroundPosition = RVec3::sZero()
 
Vec3 mGroundNormal = Vec3::sZero()
 
Vec3 mGroundVelocity = Vec3::sZero()
 
RefConst< PhysicsMaterialmGroundMaterial = PhysicsMaterial::sDefault
 
uint64 mGroundUserData = 0
 
- Protected Attributes inherited from RefTarget< CharacterBase >
atomic< uint32mRefCount
 Current reference count.
 
- Static Protected Attributes inherited from CharacterBase
static constexpr float cNoMaxSlopeAngle = 0.9999f
 
- Static Protected Attributes inherited from RefTarget< CharacterBase >
static constexpr uint32 cEmbedded
 A large value that gets added to the refcount to mark the object as embedded.
 

Detailed Description

Runtime character object. This object usually represents the player or a humanoid AI. It uses a single rigid body, usually with a capsule shape to simulate movement and collision for the character. The character is a keyframed object, the application controls it by setting the velocity.

Constructor & Destructor Documentation

◆ Character()

Character::Character ( const CharacterSettings inSettings,
RVec3Arg  inPosition,
QuatArg  inRotation,
uint64  inUserData,
PhysicsSystem inSystem 
)

Constructor

Parameters
inSettingsThe settings for the character
inPositionInitial position for the character
inRotationInitial rotation for the character (usually only around Y)
inUserDataApplication specific value
inSystemPhysics system that this character will be added to later

◆ ~Character()

Character::~Character ( )
overridevirtual

Destructor.

Member Function Documentation

◆ Activate()

void Character::Activate ( bool  inLockBodies = true)

Wake up the character.

◆ AddImpulse()

void Character::AddImpulse ( Vec3Arg  inImpulse,
bool  inLockBodies = true 
)

Add impulse to the center of mass of the character.

◆ AddLinearVelocity()

void Character::AddLinearVelocity ( Vec3Arg  inLinearVelocity,
bool  inLockBodies = true 
)

Add world space linear velocity to current velocity (m / s)

◆ AddToPhysicsSystem()

void Character::AddToPhysicsSystem ( EActivation  inActivationMode = EActivation::Activate,
bool  inLockBodies = true 
)

Add bodies and constraints to the system and optionally activate the bodies.

◆ CheckCollision()

void Character::CheckCollision ( RVec3Arg  inPosition,
QuatArg  inRotation,
Vec3Arg  inMovementDirection,
float  inMaxSeparationDistance,
const Shape inShape,
RVec3Arg  inBaseOffset,
CollideShapeCollector ioCollector,
bool  inLockBodies = true 
) const

Get all contacts for the character at a particular location.

Parameters
inPositionPosition to test.
inRotationRotation at which to test the shape.
inMovementDirectionA hint in which direction the character is moving, will be used to calculate a proper normal.
inMaxSeparationDistanceHow much distance around the character you want to report contacts in (can be 0 to match the character exactly).
inShapeShape to test collision with.
inBaseOffsetAll hit results will be returned relative to this offset, can be zero to get results in world position, but when you're testing far from the origin you get better precision by picking a position that's closer e.g. GetPosition() since floats are most accurate near the origin
ioCollectorCollision collector that receives the collision results.
inLockBodiesIf the collision query should use the locking body interface (true) or the non locking body interface (false)

◆ GetBodyID()

BodyID Character::GetBodyID ( ) const
inline

Get the body associated with this character.

◆ GetCenterOfMassPosition()

RVec3 Character::GetCenterOfMassPosition ( bool  inLockBodies = true) const

Position of the center of mass of the underlying rigid body.

◆ GetLayer()

ObjectLayer Character::GetLayer ( ) const
inline

Get the layer of the character.

◆ GetLinearVelocity()

Vec3 Character::GetLinearVelocity ( bool  inLockBodies = true) const

Get the linear velocity of the character (m / s)

◆ GetPosition()

RVec3 Character::GetPosition ( bool  inLockBodies = true) const

Get the position of the character.

◆ GetPositionAndRotation()

void Character::GetPositionAndRotation ( RVec3 outPosition,
Quat outRotation,
bool  inLockBodies = true 
) const

Get position / rotation of the body.

◆ GetRotation()

Quat Character::GetRotation ( bool  inLockBodies = true) const

Get the rotation of the character.

◆ GetTransformedShape()

TransformedShape Character::GetTransformedShape ( bool  inLockBodies = true) const

Get the transformed shape that represents the volume of the character, can be used for collision checks.

◆ GetWorldTransform()

RMat44 Character::GetWorldTransform ( bool  inLockBodies = true) const

Calculate the world transform of the character.

◆ PostSimulation()

void Character::PostSimulation ( float  inMaxSeparationDistance,
bool  inLockBodies = true 
)

Needs to be called after every PhysicsSystem::Update

Parameters
inMaxSeparationDistanceMax distance between the floor and the character to still consider the character standing on the floor
inLockBodiesIf the collision query should use the locking body interface (true) or the non locking body interface (false)

◆ RemoveFromPhysicsSystem()

void Character::RemoveFromPhysicsSystem ( bool  inLockBodies = true)

Remove bodies and constraints from the system.

◆ SetLayer()

void Character::SetLayer ( ObjectLayer  inLayer,
bool  inLockBodies = true 
)

Update the layer of the character.

◆ SetLinearAndAngularVelocity()

void Character::SetLinearAndAngularVelocity ( Vec3Arg  inLinearVelocity,
Vec3Arg  inAngularVelocity,
bool  inLockBodies = true 
)

Control the velocity of the character.

◆ SetLinearVelocity()

void Character::SetLinearVelocity ( Vec3Arg  inLinearVelocity,
bool  inLockBodies = true 
)

Set the linear velocity of the character (m / s)

◆ SetPosition()

void Character::SetPosition ( RVec3Arg  inPosition,
EActivation  inActivationMode = EActivation::Activate,
bool  inLockBodies = true 
)

Set the position of the character, optionally activating it.

◆ SetPositionAndRotation()

void Character::SetPositionAndRotation ( RVec3Arg  inPosition,
QuatArg  inRotation,
EActivation  inActivationMode = EActivation::Activate,
bool  inLockBodies = true 
) const

Set the position / rotation of the body, optionally activating it.

◆ SetRotation()

void Character::SetRotation ( QuatArg  inRotation,
EActivation  inActivationMode = EActivation::Activate,
bool  inLockBodies = true 
)

Set the rotation of the character, optionally activating it.

◆ SetShape()

bool Character::SetShape ( const Shape inShape,
float  inMaxPenetrationDepth,
bool  inLockBodies = true 
)

Switch the shape of the character (e.g. for stance). When inMaxPenetrationDepth is not FLT_MAX, it checks if the new shape collides before switching shape. Returns true if the switch succeeded.


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