LEAP Documentation 40220
Documentation for the LEAP project
ProjectXCharacterMovement.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2017. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "ProjectX.h"
8#include "Components/PrimitiveComponent.h"
10#include "ProjectXCharacterMovement.generated.h"
11
12//Flags that are now used.
13#define FLAG_IsUsingJetpack FSavedMove_Character::FLAG_Custom_0
14#define FLAG_IsUsingDash FSavedMove_Character::FLAG_Custom_1
15#define FLAG_IsUsingOmnidirectionalDash FSavedMove_Character::FLAG_Custom_2
16#define FLAG_IsUsingHookshot FSavedMove_Character::FLAG_Custom_3
17#define FLAG_IsUsingAutoClamber FSavedMove_Character::FLAG_Reserved_1
18
19DECLARE_DYNAMIC_MULTICAST_DELEGATE(FWaterRunningSignature);
20DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnCustomMovementToggledSignature, ECustomMovementType, CustomMovement, bool, bToggledState);
21
23
24/* This component is responsible for the entire replication and prediction of movement, as well as responsible for defining the behavior of our implemented custom movement modes such as: Jetpack, Hookshot and Dashes */
25UCLASS()
26class PROJECTX_API UProjectXCharacterMovement : public UCharacterMovementComponent
27{
28 GENERATED_UCLASS_BODY()
29
30public:
31 virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
32 virtual float GetMaxSpeed() const override;
33 virtual float GetGravityZ() const override;
34 virtual void CheckMaximumHeight() override;
36 virtual void UpdateFromCompressedFlags(uint8 Flags) override;
37 virtual bool ClientUpdatePositionAfterServerUpdate() override;
38 virtual class FNetworkPredictionData_Client* GetPredictionData_Client() const override;
39 virtual bool ShouldUpdateSimulationVisuals() override;
40 virtual bool CanCrouchInCurrentState() const override;
41
42 UFUNCTION(BlueprintCallable, Category = "Slope Movement")
43 float GetSlopeInstance() const { return CurrentSlopeInstance; }
44 UFUNCTION(BlueprintCallable, Category = "Slope Movement")
45 virtual float GetSlopeInstanceMultiplier() const;
46 UFUNCTION(BlueprintCallable, Category = "Slope Movement")
47 void SetSlopeInstanceMultiplierFromSpeed(const float& Speed);
48 UFUNCTION(BlueprintCallable, Category = "Slope Movement")
49 bool IsRunningOnWater() const { return GetMovementBase() && GetMovementBase()->GetCollisionObjectType() == ECC_WaterBlock; }
50 UFUNCTION(BlueprintCallable, Category = "Slope Movement")
51 float GetMaxPossibleSpeed() const;
52 UFUNCTION(BlueprintCallable)
53 float GetHookShotLength() const {return HookshotLength * HookshotLengthMultiplier;}
54 UFUNCTION(BlueprintPure, Category = Character)
55 FORCEINLINE float GetDeltaSlope() const { return DeltaSlope; }
56 UFUNCTION(BlueprintPure, Category = Character)
57 FORCEINLINE float GetCrouchSpeedModifier() const { return CrouchSpeedModifier; }
58 UFUNCTION(BlueprintPure, Category = Character)
59 FORCEINLINE float GetGroundFrictionCache() const { return GroundFrictionCache; }
60 UFUNCTION(BlueprintPure, Category = Character)
61 FORCEINLINE float GetTimeMovementStartedAt() const { return TimeMovementStartedAt; }
62 UFUNCTION(BlueprintPure, Category = Character)
63 FORCEINLINE float GetTimeMovementStoppedAt() const { return TimeMovementStoppedAt; }
64
65 /* Returns the slope instance that matches the current velocity we're traveling at. No longer needs current slope instance to be 0 to function */
66 virtual float GetCurrentSpeedSlopeInstance(bool bUse2DVelocity = false) const;
67 /* Performs the find hookable point logic for the hookshot movement */
68 virtual bool PerformHookPointSearch(FHitResult& OutHitResult) const;
69 virtual bool CanClamber(const FVector& InVelocity, FHitResult& FoundLedgeHitResult) const;
70 /* Returns true if we're hitting a ramp and need to go into falling state. */
71 virtual bool CheckForRamp(const FVector& InVelocity, float DeltaTime) const;
72 void Crouch(bool bClientSimulation) override;
73 void UnCrouch(bool bClientSimulation) override;
74 void SetupDash(FVector DesiredVelocity,bool bLookAtDashDirection = true, bool bBreakAfterDashEnds = false);
75 /* Sets up the information needed to run the overlaps on the server for the latch point and not rely on RPCs*/
76 void SetupHookshot(TArray<float> RangeChecks, float MinDotAllowed);
77 void ToggleDash(bool bToggle, bool bIsOmni = false);
78 void ToggleJetPack(bool bToggle);
79 void ToggleHookshot(bool bToggle);
80 void ToggleClamber(bool bToggle);
81
82 UFUNCTION(BlueprintPure, Category = Character)
83 FORCEINLINE float GetMaxHookshotSpeed() const { return MaxHookshotSpeed * HookshotMaxSpeedMultiplier * HookshotSpeedMultiplier ;}
84 UFUNCTION(BlueprintPure, Category = Character)
85 FORCEINLINE float GetHookshotSpeed() const { return HookshotSpeed * HookshotSpeedMultiplier; }
86 UFUNCTION(BlueprintPure, Category = Character)
87 FORCEINLINE float GetMaxHeight() const { return MaximumHeight * AltitudeLimitMultiplier; }
88
89 /* Only call this function if you can update this from both server and client */
90 void UpdateHookShotLengthMultiplier(float NewMultiplier);
91 /* Only call this function if you can update this from both server and client */
92 void UpdateHookShotSpeedMultiplier(float NewSpeedMultiplier);
93 /* Only call this function if you can update this from both server and client */
94 void UpdateHookShotMaxSpeedMultiplier(float NewSpeedMultiplier);
95 /* Only call this function if you can update this from both server and client */
96 void UpdateAltitudeLimitMultiplier(float NewAltitudeLimitMultiplier);
97 /* Only call this function if you can update this from both server and client */
98 void UpdateGravityMultiplier(float NewGravityMultiplier);
99 /* Only call this function if you can update this from both server and client */
100 void UpdateGroundSpeedMultiplier(float NewGroundSpeedMultiplier);
101
102 /* How much stamina is used by the Jetpack*/
103 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Jetpack, meta = (EditCondition = "bHasJetpack"))
104 float JetpackEnergyDrainRate = 25.f;
105 /* Maximum speed the hookshot is allowed to reach */
106 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Hookshot, meta = (EditCondition = "bCanHookshot"))
107 float MaxHookshotSpeed = 2800.f;
108
109 UPROPERTY(BlueprintAssignable)
110 FWaterRunningSignature OnClamberStart;
111 UPROPERTY(BlueprintAssignable)
112 FWaterRunningSignature OnClamberEnd;
113 UPROPERTY(BlueprintAssignable)
114 FWaterRunningSignature OnWaterRunningStart;
115 UPROPERTY(BlueprintAssignable)
116 FWaterRunningSignature OnWaterRunningEnd;
117 UPROPERTY(BlueprintAssignable)
118 FOnCustomMovementToggledSignature OnCustomMovementToggled;
119
120protected:
121 /* Responsible for handling our CurrentSlopeInstance as well as checking for any ramping behavior */
122 virtual void UpdateSlopeRunning(float DeltaTime, const float& StartingZ);
123 virtual bool DoJump(bool bReplayingMoves);
124 virtual void BeginPlay() override;
125 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
126 virtual void PerformMovement(float DeltaTime) override;
127 virtual void PhysWalking(float DeltaTime, int32 Iterations) override;
128 virtual void PhysFalling(float DeltaTime, int32 Iterations) override;
129 virtual void OnMovementModeChanged(EMovementMode PreviousMovementMode, uint8 PreviousCustomMode) override;
130
131 UFUNCTION()
132 void SettingsUpdate();
133
134 UFUNCTION()
135 virtual void OnLanded(const FHitResult& HitResult);
136 UFUNCTION()
137 virtual void OnCharacterInputDisabled();
138
139 UFUNCTION(Client, Reliable)
140 virtual void Client_Reliable_JetPackShutdown(float WorldTime);
141 UFUNCTION(Client, Reliable)
142 virtual void Client_Reliable_HookshotShutdown();
143
144 /* ----------------------------------------Base Movement------------------------------------------------------------ */
145 /* How much slower the character moves while crouched*/
146 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = CharacterBase)
147 float CrouchSpeedModifier = 0.5f;
148 /* The speed at which players fast fall. */
149 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Character Movement: Jumping / Falling", meta = (AllowPrivateAccess = true))
150 float FastFallSpeed = 1000.f;
151
152 /* ------------------------------------------------SLOPES----------------------------------------------------------- */
153 /* Current slope we've built up. */
154 UPROPERTY(Replicated, BlueprintReadOnly)
155 float CurrentSlopeInstance = 0.f;
156 /* When going up slopes, how many times more should the current slope instance be reduced by? */
157 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Slope Movement", meta = (AllowPrivateAccess = true))
158 float UpwardSlopePenalty = 1.25f;
159 /* How much should the current slope instance decay per second? */
160 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Slope Movement", meta = (AllowPrivateAccess = true))
161 float SlopeDecay = 100.f;
162 /* How much should the current slope instance increase per second if we're running on water? Will still be affected by SlopeDecay. */
163 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Slope Movement", meta = (AllowPrivateAccess = true))
164 float WaterRunningSlopeRate = 200.f;
165 /* How much should the current slope instance increase per second if we're boosting? Will still be affected by SlopeDecay. */
166 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Slope Movement", meta = (AllowPrivateAccess = true))
167 float BoostSlopeRate = 400.f;
168 /* Maximum a slope instance be changed per second */
169 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Slope Movement", meta = (AllowPrivateAccess = true))
170 float MaxDeltaSlope = 200.f;
171 /* Maximum a slope instance can be */
172 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Slope Movement", meta = (AllowPrivateAccess = true))
173 float MaxSlopeInstance = 2000.f;
174 /* How much to divide slope instance by to get our movement speed bonus */
175 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Slope Movement", meta = (AllowPrivateAccess = true))
176 float SlopeSpeedDivisor = 500.f;
177 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Slope Movement", meta = (AllowPrivateAccess = true))
178 UCurveFloat* SlopeSpeedCurve = NULL;
179 /* How much higher the slope instance can be in comparison to current speed */
180 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Slope Movement", meta = (AllowPrivateAccess = true))
181 float MaxSlopeSpeedDifference = 200.f;
182 /* Any speeds below this value will reset the current slope instance */
183 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Slope Movement", meta = (AllowPrivateAccess = true))
184 float SlopeResetSpeed = 100.f;
185 /* Distance infront of this actor we test for ramps */
186 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Ramp Movement", meta = (AllowPrivateAccess = true))
187 float RampPredictionDistance = 32.f;
188 /* Distance downward from this actor we test for ramps (not including capsule size). */
189 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Ramp Movement", meta = (AllowPrivateAccess = true))
190 float RampDownwardPredictionDistance = 32.f;
191 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Ramp Movement", meta = (AllowPrivateAccess = true))
192 float MinRampAngle = 20.f;
193 /* should the angle of the ground affect speed*/
194 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Ramp Movement", meta = (AllowPrivateAccess = true))
195 bool bUseSlopes = true;
196 /* flat boost amount*/
197 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Ramp Movement", meta = (AllowPrivateAccess = true))
198 float FlatBoostMultiplier = 1.0f;
199 /* ----------------------------------------JETPACK-------------------------------------------------------------- */
200 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Jetpack)
201 bool bHasJetpack = false;
202 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Jetpack, meta = (EditCondition = "bHasJetpack"))
203 float JetpackForce = 4000.f;
204 //Max Z velocity we can achieve with the Jetpack.
205 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Jetpack, meta = (EditCondition = "bHasJetpack"))
206 float JetpackMaxZ = 2000.f;
207 /* A curve that can be used to dynamically change the drain rate of this jetpack */
208 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Jetpack, meta = (EditCondition = "bHasJetpack"))
209 class UCurveFloat* JetpackIncreaseDrainCurve = NULL;
210
211 /* ----------------------------------------DASHES---------------------------------------------------------------- */
212 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Dash)
213 bool bCanDash = true;
214
215 /* ----------------------------------------HOOKSHOT--------------------------------------------------------------- */
216 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Hookshot)
217 bool bCanHookshot = true;
218 /* How much the does it cost to run the hookshot while it's active? */
219 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Hookshot, meta = (EditCondition = "bCanHookshot"))
220 float HookshotCostPerSecond = 5.f;
221 /* How far can the player hookshot */
222 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Hookshot, meta = (EditCondition = "bCanHookshot"))
223 float HookshotLength = 10000.f;
224 /* Incremental speed added to the hookshot each second creating an acceleration. */
225 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Hookshot, meta = (EditCondition = "bCanHookshot"))
226 float HookshotSpeed = 3500.f;
227 /* Incremental speed added to the hookshot each second creating an acceleration based on a curve. */
228 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Hookshot, meta = (EditCondition = "bCanHookshot"))
229 class UCurveFloat* IncreaseSpeedCurve = NULL;
230 /* How stiff is the hookshot spring behaviour (K constant) */
231 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Hookshot, meta = (EditCondition = "bCanHookshot"))
232 float SpringStiffness = .5f;
233 /* How stiff is the hookshot spring behaviour (K constant) */
234 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Hookshot, meta = (EditCondition = "bCanHookshot"))
235 float HookshotLatchTime = .5f;
236 /* How much vertical friction is applied during damping? */
237 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Hookshot, meta = (EditCondition = "bCanHookshot"))
238 float SpringFriction = 0.f;
239 /* If starting hookshot while above maximum velocity, how quickly to decay the velocity per second */
240 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Hookshot, meta = (EditCondition = "bCanHookshot"))
241 float HookshotDeceleration = 100.f;
242 /* How far from the hooked point to stop pulling the player towards the point */
243 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Hookshot, meta = (EditCondition = "bCanHookshot"))
244 float HookshotDisengagementDistance = 200.0f;
245
246 /* ----------------------------------------CLAMBER--------------------------------------------------------------- */
247 /* How close must the ledge be from the player before they are allowed to clamber? */
248 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Clambering", meta = (AllowPrivateAccess = true))
249 float ClamberMaxDistance = 300.0f;
250 /* Max Angle deviation from our forward acceleration that a wall can be to be considered for the clamber */
251 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Clambering", meta = (AllowPrivateAccess = true))
252 float ClamberMaxAccelerationAngleDeviation = 30.f;
253 /* Max slope the "Roof" of the surface you're trying to clamber onto can have. Imagine you're approaching a ramp from the side, the "roof" of it will be angled at X degrees, if ClamberSurfaceMaxSlope is 45 and the ramp has a 50 degrees angle, we won't clamber towards it*/
254 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Clambering", meta = (AllowPrivateAccess = true))
255 float ClamberSurfaceMaxSlope = 45.f;
256 /* Max Angle deviation From the direction you're looking at that a ledge can be for it to be considered for the clamber */
257 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Clambering", meta = (AllowPrivateAccess = true))
258 float ClamberMaxCameraDirectionAngleDeviation = 15.f;
259 /* How high can the ledge be from the player when attempting to clamber? */
260 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Clambering", meta = (AllowPrivateAccess = true))
261 float ClamberMaxHeight = 400.0f;
262 /* Upwardsforce to award the player when they can clamber */
263 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Clambering", meta = (AllowPrivateAccess = true))
264 float ClamberForce = 4000.0f;
265 /* Upwardsforce to award the player when they can clamber */
266 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Clambering", meta = (AllowPrivateAccess = true))
267 float MaxUpwardsClamberForce = 2000.0f;
268
269 uint8 bWantsToDash : 1;
270 uint8 bWantsToOmniDash : 1;
271 uint8 bWantsToJetPack : 1;
272 uint8 bWantsToHookshot : 1;
273 uint8 bWantsToAutoClamber : 1;
274
275 uint8 bWantsToDashCache : 1;
276 uint8 bWantsToOmniDashCache : 1;
277 uint8 bWantsToJetPackCache : 1;
278 uint8 bWantsToHookshotCache : 1;
279private:
280 /* A cache of this owner as an AProjectXCharacter */
281 UPROPERTY()
282 AProjectXCharacter* PXCharacterOwner = NULL;
283 /* Difference in slope between the previous frame and this one */
284 float DeltaSlope = 0.f;
285 FVector PreviousRampDirection = FVector(0, 0, 0);
286 bool bWaterRunning = false;
287 float JetpackLastEnableTime = -1.f;
288 float JetpackUsageTime = 0.f;
289 FVector DashDesiredVelocity = FVector::ZeroVector;
290 float MinDotAllowedOnHook = 0.9f;
291 TArray<float> RangeCheckFailsafes;
292 float CurrentMaxSpeed = 0.0f;
293 float MaxHookshotLength = 0.f;
294 float HookshotUsageDuration = 0.f;
295 float HookshotDisengagementDistanceSqrd = 0.0f;
296 FVector HookshotLocation = FVector::ZeroVector;
297 bool bLookTowardsDashMovement = true;
298 bool bBreakAfterDashing = false;
299 float SpeedBeforeDashing = 0.f;
300 int32 CrouchInterpolationID = INDEX_NONE;
301 float GroundFrictionCache = INDEX_NONE;
302 bool bClambering = false;
303 float CrouchSpeed = 0.5f;
304 float TimeMovementStartedAt = INDEX_NONE;
305 float TimeMovementStoppedAt = INDEX_NONE;
306 bool bWasMaximumHeightReached;
307
308 //Movement Multipliers:
309 float HookshotLengthMultiplier = 1.f;
310 float HookshotSpeedMultiplier = 1.f;
311 float HookshotMaxSpeedMultiplier = 1.f;
312 float AltitudeLimitMultiplier = 1.f;
313 float GravityMultiplier = 1.f;
314 float GroundSpeedMultiplier = 1.f;
315
316};
317
318class FSavedMove_PXMovement : public FSavedMove_Character
319{
320public:
321
322 typedef FSavedMove_Character Super;
323
325 virtual void SetMoveFor(ACharacter* Character, float InDeltaTime, FVector const& NewAccel, class FNetworkPredictionData_Client_Character& ClientData) override;
326
328 virtual uint8 GetCompressedFlags() const override;
329
331 virtual void Clear() override;
332
335 virtual bool CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* Character, float MaxDelta) const override;
336
340 virtual void PrepMoveFor(class ACharacter* Character) override;
341
347};
348
349class FNetworkPredictionData_Client_PXMovement : public FNetworkPredictionData_Client_Character
350{
351public:
352 FNetworkPredictionData_Client_PXMovement(const UCharacterMovementComponent& ClientMovement);
353
354 typedef FNetworkPredictionData_Client_Character Super;
355
357 virtual FSavedMovePtr AllocateNewMove() override;
358};
ECustomMovementType
Definition: PlayerStructs.h:15
@ Dash
Definition: DashComponent.cpp:90
#define ECC_WaterBlock
Definition: ProjectX.h:68
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnCustomMovementToggledSignature, ECustomMovementType, CustomMovement, bool, bToggledState)
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FWaterRunningSignature)
Definition: ProjectXCharacter.h:128
Definition: ProjectXCharacterMovement.h:350
FNetworkPredictionData_Client_PXMovement(const UCharacterMovementComponent &ClientMovement)
Definition: ProjectXCharacterMovement.cpp:1520
FNetworkPredictionData_Client_Character Super
Definition: ProjectXCharacterMovement.h:354
virtual FSavedMovePtr AllocateNewMove() override
Allocates a new copy of our custom saved move.
Definition: ProjectXCharacterMovement.cpp:1526
Definition: ProjectXCharacterMovement.h:319
FSavedMove_Character Super
Definition: ProjectXCharacterMovement.h:322
uint8 bSavedWantsToDash
Definition: ProjectXCharacterMovement.h:342
uint8 bSavedWantsToJetPack
Definition: ProjectXCharacterMovement.h:344
uint8 bSavedWantsToOmniDash
Definition: ProjectXCharacterMovement.h:343
uint8 bSavedWantsToAutoClamber
Definition: ProjectXCharacterMovement.h:346
uint8 bSavedWantsToHookshot
Definition: ProjectXCharacterMovement.h:345
Definition: ProjectXCharacterMovement.h:27