3#include <JoltPlugin/Character/JoltCharacterControllerComponent.h>
27 bool GetAllowJumpInAir()
const {
return m_bAllowJumpInAir; }
28 void SetAllowJumpInAir(
bool inAllow) { m_bAllowJumpInAir = inAllow; }
52 float m_fShapeRadius = 0.25f;
55 float m_fCylinderHeightCrouch = 0.9f;
58 float m_fCylinderHeightStand = 1.7f;
61 float m_fFootRadius = 0.15f;
64 float m_fWalkSpeedCrouching = 0.5f;
67 float m_fWalkSpeedStanding = 1.5f;
70 float m_fWalkSpeedRunning = 3.5f;
73 float m_fMaxStepUp = 0.25f;
76 float m_fMaxStepDown = 0.25f;
79 float m_fJumpImpulse = 5.0f;
82 bool m_bAllowJumpInAir =
false;
91 float m_fWalkInteractionDistance = 1.0f;
94 float m_fRunInteractionDistance = 3.0f;
96 void SetWalkSurfaceInteraction(
const char* szName) { m_sWalkSurfaceInteraction.
Assign(szName); }
97 const char* GetWalkSurfaceInteraction()
const {
return m_sWalkSurfaceInteraction.
GetData(); }
99 void SetFallbackWalkSurfaceFile(
const char* szFile);
100 const char* GetFallbackWalkSurfaceFile()
const;
103 float m_fAirSpeed = 2.5f;
106 float m_fAirFriction = 0.5f;
109 void SetHeadObjectReference(
const char* szReference);
115 float GetCurrentCapsuleHeight()
const;
118 float GetCurrentCylinderHeight()
const;
123 virtual bool IsTouchingGround()
override {
return m_LastGroundState == GroundState::OnGround; }
125 GroundState GetGroundState()
const {
return m_LastGroundState; }
126 bool IsStandingOnGround()
const {
return m_LastGroundState == GroundState::OnGround; }
127 bool IsSlidingOnGround()
const {
return m_LastGroundState == GroundState::Sliding; }
128 bool IsInAir()
const {
return m_LastGroundState == GroundState::InAir; }
129 virtual bool IsCrouching()
override {
return m_uiIsCrouchingBit; }
136 bool m_bAllowJump =
true;
137 bool m_bAllowCrouch =
true;
138 bool m_bApplyGroundVelocity =
true;
140 float m_fPushDownForce = 0;
142 float m_fGroundInteractionDistanceThreshold = 1.0f;
143 float m_fMaxStepUp = 0;
144 float m_fMaxStepDown = 0;
151 virtual void DetermineConfig(
Config& out_inputs);
154 virtual void ApplyRotationZ();
157 void ResetInputState();
159 void ResetInternalState();
164 void ApplyCrouchState();
167 void StoreLateralVelocity();
168 void ClampLateralVelocity();
169 void MoveHeadObject();
170 void DebugVisualizations();
174 GroundState m_LastGroundState = GroundState::InAir;
176 plUInt8 m_uiInputJumpBit : 1;
177 plUInt8 m_uiInputCrouchBit : 1;
178 plUInt8 m_uiInputRunBit : 1;
179 plUInt8 m_uiIsCrouchingBit : 1;
182 float m_fVelocityUp = 0.0f;
183 float m_fNextCylinderHeight = 0;
184 float m_fAccumulatedWalkDistance = 0.0f;
187 bool m_bFeetOnSolidGround =
false;
189 float m_fCurrentCylinderHeight = 0;
191 float m_fHeadHeightOffset = 0.0f;
192 float m_fHeadTargetHeight = 0.0f;
197 plUInt32 m_uiUserDataIndex = plInvalidIndex;
198 plUInt32 m_uiJoltBodyID = plInvalidIndex;
201 const char* DummyGetter()
const {
return nullptr; }
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
virtual void OnActivated()
This method is called when the component gets activated.
Definition Component.cpp:140
Definition ComponentManager.h:88
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
void Assign(const char(&string)[N])
Assigning a new string from a string constant is a slow operation, but the hash computation can happe...
const char * GetData() const
Gives access to the actual string data, so you can do all the typical (read-only) string operations o...
Definition HashedString_inl.h:110
Base class for character controllers (CC).
Definition JoltCharacterControllerComponent.h:27
virtual void OnSimulationStarted() override
This method is called once for active components, at the start of the next world update,...
Definition JoltCharacterControllerComponent.cpp:102
virtual float GetShapeRadius() const =0
Returns the radius of the shape. This never changes at runtime.
virtual void DeserializeComponent(plWorldReader &inout_stream) override
Override this to load the current state of the component from the given stream.
Definition JoltCharacterControllerComponent.cpp:69
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 void OnDeactivated() override
This method is called when the component gets deactivated.
Definition JoltCharacterControllerComponent.cpp:84
virtual void SerializeComponent(plWorldWriter &inout_stream) const override
Override this to save the current state of the component to the given stream.
Definition JoltCharacterControllerComponent.cpp:55
virtual void UpdateCharacter()=0
Called up to once per frame, but potentially less often, if physics updates were skipped due to high ...
An example character controller (CC) implementation build upon plJoltCharacterControllerComponent.
Definition JoltDefaultCharacterComponent.h:17
virtual bool IsCrouching() override
Checks whether the CC is currently in the crouch state.
Definition JoltDefaultCharacterComponent.h:129
plHashedString m_sWalkSurfaceInteraction
The surface interaction to spawn regularly when walking.
Definition JoltDefaultCharacterComponent.h:85
GroundState
Definition JoltDefaultCharacterComponent.h:42
virtual bool IsTouchingGround() override
Checks whether the CC is currently touching the ground.
Definition JoltDefaultCharacterComponent.h:123
plSurfaceResourceHandle m_hFallbackWalkSurface
The surface type to use for interactions, when no other surface type is available.
Definition JoltDefaultCharacterComponent.h:88
static constexpr plVec2Template< float > MakeZero()
Definition Vec2.h:49
static plVec3Template< float > MakeZero()
Definition Vec3.h:38
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
A handle to a game object.
Definition Declarations.h:76
Definition JoltDefaultCharacterComponent.h:135
This message is sent when animation root motion data is available.
Definition Declarations.h:109
Definition CharacterControllerComponent.h:10
Definition UpdateLocalBoundsMessage.h:9