3#include <Core/World/World.h>
4#include <JoltPlugin/JoltPluginDLL.h>
5#include <JoltPlugin/System/JoltCollisionFiltering.h>
6#include <GameEngine/Physics/CharacterControllerComponent.h>
13 class CharacterVirtual;
17PL_DECLARE_FLAGS(plUInt32, plJoltCharacterDebugFlags, PrintState, VisShape, VisContacts, VisCasts, VisGroundContact, VisFootCheck);
18PL_DECLARE_REFLECTABLE_TYPE(PL_JOLTPLUGIN_DLL, plJoltCharacterDebugFlags);
51 float m_fCastFraction = 0.0f;
56 JPH::SubShapeID m_SubShapeID;
65 void SetObjectToIgnore(plUInt32 uiObjectFilterID);
68 void ClearObjectToIgnore();
72 plUInt8 m_uiCollisionLayer = 0;
75 plUInt8 m_uiPresenceCollisionLayer = 0;
81 void SetMaxClimbingSlope(
plAngle slope);
82 plAngle GetMaxClimbingSlope()
const {
return m_MaxClimbingSlope; }
85 void SetMass(
float fMass);
86 float GetMass()
const {
return m_fMass; }
89 void SetStrength(
float fStrength);
90 float GetStrength()
const {
return m_fStrength; }
126 float m_fMass = 70.0f;
127 float m_fStrength = 500.0f;
155 const JPH::CharacterVirtual* GetJoltCharacter()
const {
return m_pCharacter; }
158 plResult TryChangeShape(JPH::Shape* pNewShape);
161 void RawMoveWithVelocity(
const plVec3& vVelocity,
float fMaxStairStepUp,
float fMaxStepDown);
164 void RawMoveIntoDirection(
const plVec3& vDirection);
167 void RawMoveToPosition(
const plVec3& vTargetPosition);
170 void TeleportToPosition(
const plVec3& vGlobalFootPos);
175 bool StickToGround(
float fMaxDist);
191 plVec3 GetContactVelocityAndPushAway(
const ContactPoint& contact,
float fPushForce);
199 void VisualizeContact(
const ContactPoint& contact,
const plColor& color)
const;
207 void Update(
plTime deltaTime);
209 float m_fUpdateTimeDelta = 0.1f;
210 float m_fInverseUpdateTimeDelta = 1.0f;
211 JPH::CharacterVirtual* m_pCharacter =
nullptr;
213 void CreatePresenceBody();
214 void RemovePresenceBody();
215 void MovePresenceBody(
plTime deltaTime);
217 plUInt32 m_uiPresenceBodyID = plInvalidIndex;
218 plUInt32 m_uiPresenceBodyAddCounter = 0;
221 plUInt32 m_uiUserDataIndex = plInvalidIndex;
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
static constexpr plAngle MakeFromDegree(float fDegree)
Creates an instance of plAngle that was initialized from degree. (Performs a conversion)
Definition Angle_inl.h:33
Base class for implementations of a character controller.
Definition CharacterControllerComponent.h:30
virtual void DeserializeComponent(plWorldReader &inout_stream) override
Override this to load the current state of the component from the given stream.
Definition CharacterControllerComponent.cpp:64
virtual void SerializeComponent(plWorldWriter &inout_stream) const override
Override this to save the current state of the component to the given stream.
Definition CharacterControllerComponent.cpp:58
plColor represents an RGBA color in linear color space. Values are stored as float,...
Definition Color.h:44
virtual void OnDeactivated()
This method is called when the component gets deactivated.
Definition Component.cpp:142
virtual void OnSimulationStarted()
This method is called once for active components, at the start of the next world update,...
Definition Component.cpp:144
Definition DynamicArray.h:81
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
Definition JoltCollisionFiltering.h:103
Base class for character controllers (CC).
Definition JoltCharacterControllerComponent.h:27
virtual float GetShapeRadius() const =0
Returns the radius of the shape. This never changes at runtime.
plBitflags< plJoltCharacterDebugFlags > m_DebugFlags
What aspects of the CC to visualize.
Definition JoltCharacterControllerComponent.h:78
PL_ALWAYS_INLINE float GetInverseUpdateTimeDelta() const
Returns the inverse of update time delta.
Definition JoltCharacterControllerComponent.h:134
PL_ALWAYS_INLINE float GetUpdateTimeDelta() const
Returns the time delta to use for updating the character. This may differ from the world delta.
Definition JoltCharacterControllerComponent.h:131
virtual void RawMove(const plVec3 &vMoveDeltaGlobal) override
Attempts to move the character into the given direction.
Definition JoltCharacterControllerComponent.h:97
virtual void TeleportCharacter(const plVec3 &vGlobalFootPos) override
Teleports the CC to the desired global position. Ignores obstacles on the path.
Definition JoltCharacterControllerComponent.h:108
virtual JPH::Ref< JPH::Shape > MakeNextCharacterShape()=0
Returns the shape that the character is supposed to use next.
virtual bool IsTouchingGround() override
Checks whether the CC is currently touching the ground.
Definition JoltCharacterControllerComponent.h:119
virtual bool IsCrouching() override
Checks whether the CC is currently in the crouch state.
Definition JoltCharacterControllerComponent.h:122
virtual void UpdateCharacter()=0
Called up to once per frame, but potentially less often, if physics updates were skipped due to high ...
virtual void MoveCharacter(plMsgMoveCharacterController &msg) override
Instructs the CC to move in certain directions. An implementation can queue the request for later pro...
Definition JoltCharacterControllerComponent.h:102
JPH::CharacterVirtual * GetJoltCharacter()
Gives access to the internally used JPH::CharacterVirtual.
Definition JoltCharacterControllerComponent.h:154
virtual bool IsDestinationUnobstructed(const plVec3 &vGlobalFootPos, float fCharacterHeight) override
Checks whether the CC can be teleported to the target position without getting stuck.
Definition JoltCharacterControllerComponent.h:116
Definition JoltWorldModule.h:29
Reads a world description from a stream. Allows to instantiate that world multiple times in different...
Definition WorldReader.h:47
Stores an entire plWorld in a stream.
Definition WorldWriter.h:13
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
Definition CharacterControllerComponent.h:10
Definition UpdateLocalBoundsMessage.h:9
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12