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

#include <CharacterVirtual.h>

Inheritance diagram for CharacterVirtual:
CharacterBase RefTarget< CharacterBase > NonCopyable

Classes

struct  Contact
 
struct  ExtendedUpdateSettings
 Settings struct with settings for ExtendedUpdate. More...
 

Public Types

using TempContactList = Array< Contact, STLTempAllocator< Contact > >
 
using ContactList = Array< Contact >
 
- Public Types inherited from CharacterBase
enum class  EGroundState { OnGround , OnSteepGround , NotSupported , InAir }
 

Public Member Functions

JPH_OVERRIDE_NEW_DELETE CharacterVirtual (const CharacterVirtualSettings *inSettings, RVec3Arg inPosition, QuatArg inRotation, uint64 inUserData, PhysicsSystem *inSystem)
 
 CharacterVirtual (const CharacterVirtualSettings *inSettings, RVec3Arg inPosition, QuatArg inRotation, PhysicsSystem *inSystem)
 Constructor without user data.
 
virtual ~CharacterVirtual () override
 Destructor.
 
void SetListener (CharacterContactListener *inListener)
 Set the contact listener.
 
CharacterContactListenerGetListener () const
 Get the current contact listener.
 
void SetCharacterVsCharacterCollision (CharacterVsCharacterCollision *inCharacterVsCharacterCollision)
 Set the character vs character collision interface.
 
Vec3 GetLinearVelocity () const
 Get the linear velocity of the character (m / s)
 
void SetLinearVelocity (Vec3Arg inLinearVelocity)
 Set the linear velocity of the character (m / s)
 
RVec3 GetPosition () const
 Get the position of the character.
 
void SetPosition (RVec3Arg inPosition)
 Set the position of the character.
 
Quat GetRotation () const
 Get the rotation of the character.
 
void SetRotation (QuatArg inRotation)
 Set the rotation of the character.
 
RVec3 GetCenterOfMassPosition () const
 
RMat44 GetWorldTransform () const
 Calculate the world transform of the character.
 
RMat44 GetCenterOfMassTransform () const
 Calculates the transform for this character's center of mass.
 
float GetMass () const
 Character mass (kg)
 
void SetMass (float inMass)
 
float GetMaxStrength () const
 Maximum force with which the character can push other bodies (N)
 
void SetMaxStrength (float inMaxStrength)
 
float GetPenetrationRecoverySpeed () const
 This value governs how fast a penetration will be resolved, 0 = nothing is resolved, 1 = everything in one update.
 
void SetPenetrationRecoverySpeed (float inSpeed)
 
bool GetEnhancedInternalEdgeRemoval () const
 Set to indicate that extra effort should be made to try to remove ghost contacts (collisions with internal edges of a mesh). This is more expensive but makes bodies move smoother over a mesh with convex edges.
 
void SetEnhancedInternalEdgeRemoval (bool inApply)
 
float GetCharacterPadding () const
 Character padding.
 
uint GetMaxNumHits () const
 Max num hits to collect in order to avoid excess of contact points collection.
 
void SetMaxNumHits (uint inMaxHits)
 
float GetHitReductionCosMaxAngle () const
 Cos(angle) where angle is the maximum angle between two hits contact normals that are allowed to be merged during hit reduction. Default is around 2.5 degrees. Set to -1 to turn off.
 
void SetHitReductionCosMaxAngle (float inCosMaxAngle)
 
bool GetMaxHitsExceeded () const
 
Vec3 GetShapeOffset () const
 An extra offset applied to the shape in local space. This allows applying an extra offset to the shape in local space. Note that setting it on the fly can cause the shape to teleport into collision.
 
void SetShapeOffset (Vec3Arg inShapeOffset)
 
uint64 GetUserData () const
 Access to the user data, can be used for anything by the application.
 
void SetUserData (uint64 inUserData)
 
BodyID GetInnerBodyID () const
 Optional inner rigid body that proxies the character in the world. Can be used to update body properties.
 
Vec3 CancelVelocityTowardsSteepSlopes (Vec3Arg inDesiredVelocity) const
 
void Update (float inDeltaTime, Vec3Arg inGravity, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator)
 
bool CanWalkStairs (Vec3Arg inLinearVelocity) const
 
bool WalkStairs (float inDeltaTime, Vec3Arg inStepUp, Vec3Arg inStepForward, Vec3Arg inStepForwardTest, Vec3Arg inStepDownExtra, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator)
 
bool StickToFloor (Vec3Arg inStepDown, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator)
 
void ExtendedUpdate (float inDeltaTime, Vec3Arg inGravity, const ExtendedUpdateSettings &inSettings, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator)
 
void RefreshContacts (const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator)
 This function can be used after a character has teleported to determine the new contacts with the world.
 
void UpdateGroundVelocity ()
 
bool SetShape (const Shape *inShape, float inMaxPenetrationDepth, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator)
 
void SetInnerBodyShape (const Shape *inShape)
 Updates the shape of the inner rigid body. Should be called after a successful call to SetShape.
 
TransformedShape GetTransformedShape () 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, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter) const
 Get all contacts for the character at a particular location. When colliding with another character virtual, this pointer will be provided through CollideShapeCollector::SetUserContext before adding a hit.
 
virtual void SaveState (StateRecorder &inStream) const override
 
virtual void RestoreState (StateRecorder &inStream) override
 
const ContactListGetActiveContacts () const
 Access to the internal list of contacts that the character has found.
 
bool HasCollidedWith (const BodyID &inBody) const
 Check if the character is currently in contact with or has collided with another body in the last time step.
 
bool HasCollidedWith (const CharacterVirtual *inCharacter) const
 Check if the character is currently in contact with or has collided with another character in the last time step.
 
- 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.
 
- 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
 

Static Public Attributes

static bool sDrawConstraints = false
 Draw the current state of the constraints for iteration 0 when creating them.
 
static bool sDrawWalkStairs = false
 Draw the state of the walk stairs algorithm.
 
static bool sDrawStickToFloor = false
 Draw the state of the stick to floor algorithm.
 

Additional Inherited Members

- 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. Contrary to the Character class it doesn't use a rigid body but moves doing collision checks only (hence the name virtual). The advantage of this is that you can determine when the character moves in the frame (usually this has to happen at a very particular point in the frame) but the downside is that other objects don't see this virtual character. In order to make this work it is recommended to pair a CharacterVirtual with a Character that moves along. This Character should be keyframed (or at least have no gravity) and move along with the CharacterVirtual so that other rigid bodies can collide with it.

Member Typedef Documentation

◆ ContactList

◆ TempContactList

Constructor & Destructor Documentation

◆ CharacterVirtual() [1/2]

CharacterVirtual::CharacterVirtual ( const CharacterVirtualSettings 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 the up-axis)
inUserDataApplication specific value
inSystemPhysics system that this character will be added to

◆ CharacterVirtual() [2/2]

CharacterVirtual::CharacterVirtual ( const CharacterVirtualSettings inSettings,
RVec3Arg  inPosition,
QuatArg  inRotation,
PhysicsSystem inSystem 
)
inline

Constructor without user data.

◆ ~CharacterVirtual()

CharacterVirtual::~CharacterVirtual ( )
overridevirtual

Destructor.

Member Function Documentation

◆ CancelVelocityTowardsSteepSlopes()

Vec3 CharacterVirtual::CancelVelocityTowardsSteepSlopes ( Vec3Arg  inDesiredVelocity) const

This function can be called prior to calling Update() to convert a desired velocity into a velocity that won't make the character move further onto steep slopes. This velocity can then be set on the character using SetLinearVelocity()

Parameters
inDesiredVelocityVelocity to clamp against steep walls
Returns
A new velocity vector that won't make the character move up steep slopes

◆ CanWalkStairs()

bool CharacterVirtual::CanWalkStairs ( Vec3Arg  inLinearVelocity) const

This function will return true if the character has moved into a slope that is too steep (e.g. a vertical wall). You would call WalkStairs to attempt to step up stairs.

Parameters
inLinearVelocityThe linear velocity that the player desired. This is used to determine if we're pushing into a step.

◆ CheckCollision()

void CharacterVirtual::CheckCollision ( RVec3Arg  inPosition,
QuatArg  inRotation,
Vec3Arg  inMovementDirection,
float  inMaxSeparationDistance,
const Shape inShape,
RVec3Arg  inBaseOffset,
CollideShapeCollector ioCollector,
const BroadPhaseLayerFilter inBroadPhaseLayerFilter,
const ObjectLayerFilter inObjectLayerFilter,
const BodyFilter inBodyFilter,
const ShapeFilter inShapeFilter 
) const

Get all contacts for the character at a particular location. When colliding with another character virtual, this pointer will be provided through CollideShapeCollector::SetUserContext before adding a hit.

Parameters
inPositionPosition to test, note that this position will be corrected for the character padding.
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.
inBroadPhaseLayerFilterFilter that is used to check if the character collides with something in the broadphase.
inObjectLayerFilterFilter that is used to check if a character collides with a layer.
inBodyFilterFilter that is used to check if a character collides with a body.
inShapeFilterFilter that is used to check if a character collides with a subshape.

◆ ExtendedUpdate()

void CharacterVirtual::ExtendedUpdate ( float  inDeltaTime,
Vec3Arg  inGravity,
const ExtendedUpdateSettings inSettings,
const BroadPhaseLayerFilter inBroadPhaseLayerFilter,
const ObjectLayerFilter inObjectLayerFilter,
const BodyFilter inBodyFilter,
const ShapeFilter inShapeFilter,
TempAllocator inAllocator 
)

This function combines Update, StickToFloor and WalkStairs. This function serves as an example of how these functions could be combined. Before calling, call SetLinearVelocity to update the horizontal/vertical speed of the character, typically this is:

  • When on OnGround and not moving away from ground: velocity = GetGroundVelocity() + horizontal speed as input by player + optional vertical jump velocity + delta time * gravity
  • Else: velocity = current vertical velocity + horizontal speed as input by player + delta time * gravity
    Parameters
    inDeltaTimeTime step to simulate.
    inGravityGravity vector (m/s^2). This gravity vector is only used when the character is standing on top of another object to apply downward force.
    inSettingsA structure containing settings for the algorithm.
    inBroadPhaseLayerFilterFilter that is used to check if the character collides with something in the broadphase.
    inObjectLayerFilterFilter that is used to check if a character collides with a layer.
    inBodyFilterFilter that is used to check if a character collides with a body.
    inShapeFilterFilter that is used to check if a character collides with a subshape.
    inAllocatorAn allocator for temporary allocations. All memory will be freed by the time this function returns.

◆ GetActiveContacts()

const ContactList & CharacterVirtual::GetActiveContacts ( ) const
inline

Access to the internal list of contacts that the character has found.

◆ GetCenterOfMassPosition()

RVec3 CharacterVirtual::GetCenterOfMassPosition ( ) const
inline

◆ GetCenterOfMassTransform()

RMat44 CharacterVirtual::GetCenterOfMassTransform ( ) const
inline

Calculates the transform for this character's center of mass.

◆ GetCharacterPadding()

float CharacterVirtual::GetCharacterPadding ( ) const
inline

Character padding.

◆ GetEnhancedInternalEdgeRemoval()

bool CharacterVirtual::GetEnhancedInternalEdgeRemoval ( ) const
inline

Set to indicate that extra effort should be made to try to remove ghost contacts (collisions with internal edges of a mesh). This is more expensive but makes bodies move smoother over a mesh with convex edges.

◆ GetHitReductionCosMaxAngle()

float CharacterVirtual::GetHitReductionCosMaxAngle ( ) const
inline

Cos(angle) where angle is the maximum angle between two hits contact normals that are allowed to be merged during hit reduction. Default is around 2.5 degrees. Set to -1 to turn off.

◆ GetInnerBodyID()

BodyID CharacterVirtual::GetInnerBodyID ( ) const
inline

Optional inner rigid body that proxies the character in the world. Can be used to update body properties.

◆ GetLinearVelocity()

Vec3 CharacterVirtual::GetLinearVelocity ( ) const
inline

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

◆ GetListener()

CharacterContactListener * CharacterVirtual::GetListener ( ) const
inline

Get the current contact listener.

◆ GetMass()

float CharacterVirtual::GetMass ( ) const
inline

Character mass (kg)

◆ GetMaxHitsExceeded()

bool CharacterVirtual::GetMaxHitsExceeded ( ) const
inline

Returns if we exceeded the maximum number of hits during the last collision check and had to discard hits based on distance. This can be used to find areas that have too complex geometry for the character to navigate properly. To solve you can either increase the max number of hits or simplify the geometry. Note that the character simulation will try to do its best to select the most relevant contacts to avoid the character from getting stuck.

◆ GetMaxNumHits()

uint CharacterVirtual::GetMaxNumHits ( ) const
inline

Max num hits to collect in order to avoid excess of contact points collection.

◆ GetMaxStrength()

float CharacterVirtual::GetMaxStrength ( ) const
inline

Maximum force with which the character can push other bodies (N)

◆ GetPenetrationRecoverySpeed()

float CharacterVirtual::GetPenetrationRecoverySpeed ( ) const
inline

This value governs how fast a penetration will be resolved, 0 = nothing is resolved, 1 = everything in one update.

◆ GetPosition()

RVec3 CharacterVirtual::GetPosition ( ) const
inline

Get the position of the character.

◆ GetRotation()

Quat CharacterVirtual::GetRotation ( ) const
inline

Get the rotation of the character.

◆ GetShapeOffset()

Vec3 CharacterVirtual::GetShapeOffset ( ) const
inline

An extra offset applied to the shape in local space. This allows applying an extra offset to the shape in local space. Note that setting it on the fly can cause the shape to teleport into collision.

◆ GetTransformedShape()

TransformedShape CharacterVirtual::GetTransformedShape ( ) const
inline

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

◆ GetUserData()

uint64 CharacterVirtual::GetUserData ( ) const
inline

Access to the user data, can be used for anything by the application.

◆ GetWorldTransform()

RMat44 CharacterVirtual::GetWorldTransform ( ) const
inline

Calculate the world transform of the character.

◆ HasCollidedWith() [1/2]

bool CharacterVirtual::HasCollidedWith ( const BodyID inBody) const
inline

Check if the character is currently in contact with or has collided with another body in the last time step.

◆ HasCollidedWith() [2/2]

bool CharacterVirtual::HasCollidedWith ( const CharacterVirtual inCharacter) const
inline

Check if the character is currently in contact with or has collided with another character in the last time step.

◆ RefreshContacts()

void CharacterVirtual::RefreshContacts ( const BroadPhaseLayerFilter inBroadPhaseLayerFilter,
const ObjectLayerFilter inObjectLayerFilter,
const BodyFilter inBodyFilter,
const ShapeFilter inShapeFilter,
TempAllocator inAllocator 
)

This function can be used after a character has teleported to determine the new contacts with the world.

◆ RestoreState()

void CharacterVirtual::RestoreState ( StateRecorder inStream)
overridevirtual

Reimplemented from CharacterBase.

◆ SaveState()

void CharacterVirtual::SaveState ( StateRecorder inStream) const
overridevirtual

Reimplemented from CharacterBase.

◆ SetCharacterVsCharacterCollision()

void CharacterVirtual::SetCharacterVsCharacterCollision ( CharacterVsCharacterCollision inCharacterVsCharacterCollision)
inline

Set the character vs character collision interface.

◆ SetEnhancedInternalEdgeRemoval()

void CharacterVirtual::SetEnhancedInternalEdgeRemoval ( bool  inApply)
inline

◆ SetHitReductionCosMaxAngle()

void CharacterVirtual::SetHitReductionCosMaxAngle ( float  inCosMaxAngle)
inline

◆ SetInnerBodyShape()

void CharacterVirtual::SetInnerBodyShape ( const Shape inShape)

Updates the shape of the inner rigid body. Should be called after a successful call to SetShape.

◆ SetLinearVelocity()

void CharacterVirtual::SetLinearVelocity ( Vec3Arg  inLinearVelocity)
inline

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

◆ SetListener()

void CharacterVirtual::SetListener ( CharacterContactListener inListener)
inline

Set the contact listener.

◆ SetMass()

void CharacterVirtual::SetMass ( float  inMass)
inline

◆ SetMaxNumHits()

void CharacterVirtual::SetMaxNumHits ( uint  inMaxHits)
inline

◆ SetMaxStrength()

void CharacterVirtual::SetMaxStrength ( float  inMaxStrength)
inline

◆ SetPenetrationRecoverySpeed()

void CharacterVirtual::SetPenetrationRecoverySpeed ( float  inSpeed)
inline

◆ SetPosition()

void CharacterVirtual::SetPosition ( RVec3Arg  inPosition)
inline

Set the position of the character.

◆ SetRotation()

void CharacterVirtual::SetRotation ( QuatArg  inRotation)
inline

Set the rotation of the character.

◆ SetShape()

bool CharacterVirtual::SetShape ( const Shape inShape,
float  inMaxPenetrationDepth,
const BroadPhaseLayerFilter inBroadPhaseLayerFilter,
const ObjectLayerFilter inObjectLayerFilter,
const BodyFilter inBodyFilter,
const ShapeFilter inShapeFilter,
TempAllocator inAllocator 
)

Switch the shape of the character (e.g. for stance).

Parameters
inShapeThe shape to switch to.
inMaxPenetrationDepthWhen inMaxPenetrationDepth is not FLT_MAX, it checks if the new shape collides before switching shape. This is the max penetration we're willing to accept after the switch.
inBroadPhaseLayerFilterFilter that is used to check if the character collides with something in the broadphase.
inObjectLayerFilterFilter that is used to check if a character collides with a layer.
inBodyFilterFilter that is used to check if a character collides with a body.
inShapeFilterFilter that is used to check if a character collides with a subshape.
inAllocatorAn allocator for temporary allocations. All memory will be freed by the time this function returns.
Returns
Returns true if the switch succeeded.

◆ SetShapeOffset()

void CharacterVirtual::SetShapeOffset ( Vec3Arg  inShapeOffset)
inline

◆ SetUserData()

void CharacterVirtual::SetUserData ( uint64  inUserData)

◆ StickToFloor()

bool CharacterVirtual::StickToFloor ( Vec3Arg  inStepDown,
const BroadPhaseLayerFilter inBroadPhaseLayerFilter,
const ObjectLayerFilter inObjectLayerFilter,
const BodyFilter inBodyFilter,
const ShapeFilter inShapeFilter,
TempAllocator inAllocator 
)

This function can be used to artificially keep the character to the floor. Normally when a character is on a small step and starts moving horizontally, the character will lose contact with the floor because the initial vertical velocity is zero while the horizontal velocity is quite high. To prevent the character from losing contact with the floor, we do an additional collision check downwards and if we find the floor within a certain distance, we project the character onto the floor.

Parameters
inStepDownMax amount to project the character downwards (if no floor is found within this distance, the function will return false)
inBroadPhaseLayerFilterFilter that is used to check if the character collides with something in the broadphase.
inObjectLayerFilterFilter that is used to check if a character collides with a layer.
inBodyFilterFilter that is used to check if a character collides with a body.
inShapeFilterFilter that is used to check if a character collides with a subshape.
inAllocatorAn allocator for temporary allocations. All memory will be freed by the time this function returns.
Returns
True if the character was successfully projected onto the floor.

◆ Update()

void CharacterVirtual::Update ( float  inDeltaTime,
Vec3Arg  inGravity,
const BroadPhaseLayerFilter inBroadPhaseLayerFilter,
const ObjectLayerFilter inObjectLayerFilter,
const BodyFilter inBodyFilter,
const ShapeFilter inShapeFilter,
TempAllocator inAllocator 
)

This is the main update function. It moves the character according to its current velocity (the character is similar to a kinematic body in the sense that you set the velocity and the character will follow unless collision is blocking the way). Note it's your own responsibility to apply gravity to the character velocity! Different surface materials (like ice) can be emulated by getting the ground material and adjusting the velocity and/or the max slope angle accordingly every frame.

Parameters
inDeltaTimeTime step to simulate.
inGravityGravity vector (m/s^2). This gravity vector is only used when the character is standing on top of another object to apply downward force.
inBroadPhaseLayerFilterFilter that is used to check if the character collides with something in the broadphase.
inObjectLayerFilterFilter that is used to check if a character collides with a layer.
inBodyFilterFilter that is used to check if a character collides with a body.
inShapeFilterFilter that is used to check if a character collides with a subshape.
inAllocatorAn allocator for temporary allocations. All memory will be freed by the time this function returns.

◆ UpdateGroundVelocity()

void CharacterVirtual::UpdateGroundVelocity ( )

Use the ground body ID to get an updated estimate of the ground velocity. This function can be used if the ground body has moved / changed velocity and you want a new estimate of the ground velocity. It will not perform collision detection, so is less accurate than RefreshContacts but a lot faster.

◆ WalkStairs()

bool CharacterVirtual::WalkStairs ( float  inDeltaTime,
Vec3Arg  inStepUp,
Vec3Arg  inStepForward,
Vec3Arg  inStepForwardTest,
Vec3Arg  inStepDownExtra,
const BroadPhaseLayerFilter inBroadPhaseLayerFilter,
const ObjectLayerFilter inObjectLayerFilter,
const BodyFilter inBodyFilter,
const ShapeFilter inShapeFilter,
TempAllocator inAllocator 
)

When stair walking is needed, you can call the WalkStairs function to cast up, forward and down again to try to find a valid position

Parameters
inDeltaTimeTime step to simulate.
inStepUpThe direction and distance to step up (this corresponds to the max step height)
inStepForwardThe direction and distance to step forward after the step up
inStepForwardTestWhen running at a high frequency, inStepForward can be very small and it's likely that you hit the side of the stairs on the way down. This could produce a normal that violates the max slope angle. If this happens, we test again using this distance from the up position to see if we find a valid slope.
inStepDownExtraAn additional translation that is added when stepping down at the end. Allows you to step further down than up. Set to zero if you don't want this. Should be in the opposite direction of up.
inBroadPhaseLayerFilterFilter that is used to check if the character collides with something in the broadphase.
inObjectLayerFilterFilter that is used to check if a character collides with a layer.
inBodyFilterFilter that is used to check if a character collides with a body.
inShapeFilterFilter that is used to check if a character collides with a subshape.
inAllocatorAn allocator for temporary allocations. All memory will be freed by the time this function returns.
Returns
true if the stair walk was successful

Member Data Documentation

◆ sDrawConstraints

bool CharacterVirtual::sDrawConstraints = false
inlinestatic

Draw the current state of the constraints for iteration 0 when creating them.

◆ sDrawStickToFloor

bool CharacterVirtual::sDrawStickToFloor = false
inlinestatic

Draw the state of the stick to floor algorithm.

◆ sDrawWalkStairs

bool CharacterVirtual::sDrawWalkStairs = false
inlinestatic

Draw the state of the walk stairs algorithm.


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