LEAP Documentation 40220
Documentation for the LEAP project
VehicleMovementComponent.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2018. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "GameFramework/CharacterMovementComponent.h"
7#include "VehicleMovementComponent.generated.h"
8
9#define FLAG_IsUsingBoost FSavedMove_Character::FLAG_Custom_0
10#define FLAG_IsSteeringRight FSavedMove_Character::FLAG_Custom_1
11#define FLAG_IsSteeringLeft FSavedMove_Character::FLAG_Custom_2
12#define FLAG_IsUsingUpwardsBoost FSavedMove_Character::FLAG_Custom_3
13
14UCLASS(Blueprintable)
15class PROJECTX_API UProjectXVehicleMovementComponent : public UCharacterMovementComponent
16{
17 GENERATED_UCLASS_BODY()
18public:
20 UPROPERTY(EditDefaultsOnly, Category = "Flying")
21 float GravityFallDetectionDistance = 300.0f;
22 UPROPERTY(EditDefaultsOnly, Category = "Flying")
23 bool bRightInputIsSteering = false;
24 UPROPERTY(EditDefaultsOnly, Category = "Flying", meta = (EditCondition = "bRightInputIsSteering"))
25 float SteeringRate = 100.0f;
26 UPROPERTY(EditDefaultsOnly, Category = "Flying")
27 float FlightDownwardsMultiplier = 2.0f;
28
29 virtual class FNetworkPredictionData_Client* GetPredictionData_Client() const override;
30
31 //UFUNCTION(BlueprintPure, Category = "Character Movement (Acceleration)")
32 //bool IsAccelerating(const EAccelerationDirection Direction) const;
33 UFUNCTION(BlueprintPure)
34 bool IsGroundedInFlyingMode() const { return bIsGroundedInFlyingMode; }
35 UFUNCTION(BlueprintPure, Category = "Character Movement (Acceleration)")
36 FORCEINLINE uint8 GetPackedAcceleration() const {return PackedAcceleration;}
37 UFUNCTION(BlueprintPure, Category = Character)
38 FORCEINLINE float GetFlySpeedCache() const { return FlySpeedCache; }
39 virtual float GetMaxAcceleration() const override;
40 void CalcVelocity(float DeltaTime, float Friction, bool bFluid, float BrakingDeceleration) override;
41 void UpdateAltitudeLimitMultiplier(float NewAltitudeLimitMultiplier);
42
43 uint8 bWantsToBoost : 1;
46 uint8 bWantsSteerLeft : 1;
47protected:
48 /* The speed at we smoothly rotate towards our desired vehicle rotation */
49 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Movement (Rotation Settings)")
50 float SmoothRotationRate = 4.f;
51
52 virtual void BeginPlay() override;
53 virtual bool ShouldUpdateSimulationVisuals() override;
54 virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
55 virtual float GetMaxSpeed() const override;
56 virtual void UpdateFromCompressedFlags(uint8 Flags) override;
57 virtual FVector GetFloorNormalAngle() const { return FloorNormalAngle; }
58 virtual bool CanAttemptJump() const override;
59 virtual void PhysicsRotation(float DeltaTime) override;
60 virtual bool ClientUpdatePositionAfterServerUpdate() override;
61 void PackAcceleration();
62 virtual FVector GetFallingLateralAcceleration(float DeltaTime) override;
63 FVector LinearVelocityLocal = FVector::ZeroVector;
65
66 UPROPERTY(BlueprintReadWrite,VisibleAnywhere, Category = Vehicle)
67 TArray<UPrimitiveComponent*> CollisionComponents;
68 UPrimitiveComponent* BlockedComponent = NULL;
69
70 uint8 PackedAcceleration = 0;
71 /* how much air control will affect lateral movement*/
72 UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
73 float LateralAirControl = 1.0f;
74 /* how much air control will affect forward movement*/
75 UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
76 float ForwardAirControl = 1.0f;
77 /* override the standard fluid friction that is applied*/
78 UPROPERTY(EditDefaultsOnly, Category = "Character Movement: Flying")
79 float FluidFrictionOverride = 0.0f;
80 /* can the vehicle boost while falling*/
81 UPROPERTY(EditDefaultsOnly, Category = "CharacterMovement: Jumping / Falling")
82 bool bBoostWhileFalling = false;
83 /* how fast can we boost upwards? */
84 UPROPERTY(EditDefaultsOnly, Category = Jetpack, meta = (EditCondition = "bBoostWhileFalling"))
85 float UpwardsBoostForce = 4000.f;
86 //Max Z velocity we can achieve with the Jetpack.
87 UPROPERTY(EditDefaultsOnly, Category = Jetpack, meta = (EditCondition = "bBoostWhileFalling"))
88 float UpwardsBoostMaxZ = 2000.f;
89
90 FVector AccelerationUnlessZero;
91 float AccumulatedRotationRate = 0.f;
92 float FlySpeedCache = INDEX_NONE;
93 float RotationSpeed;
94 bool bUseCustomCollisionShapes = false;
95 FVector FloorNormalAngle;
96 bool bIsGroundedInFlyingMode = false;
97 friend class AProjectXVehicle;
98};
99
100class FSavedMove_PXVehicleMovement : public FSavedMove_Character
101{
102public:
103
104 typedef FSavedMove_Character Super;
105
107 virtual void SetMoveFor(ACharacter* Character, float InDeltaTime, FVector const& NewAccel, class FNetworkPredictionData_Client_Character& ClientData) override;
108
110 virtual uint8 GetCompressedFlags() const override;
111
113 virtual void Clear() override;
114
117 virtual bool CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* Character, float MaxDelta) const override;
118
122 virtual void PrepMoveFor(class ACharacter* Character) override;
123
128};
129
130class FNetworkPredictionData_Client_PXVehicleMovement : public FNetworkPredictionData_Client_Character
131{
132public:
133 FNetworkPredictionData_Client_PXVehicleMovement(const UCharacterMovementComponent& ClientMovement);
134
135 typedef FNetworkPredictionData_Client_Character Super;
136
138 virtual FSavedMovePtr AllocateNewMove() override;
139};
Definition: ProjectXVehicle.h:56
Definition: VehicleMovementComponent.h:131
FNetworkPredictionData_Client_PXVehicleMovement(const UCharacterMovementComponent &ClientMovement)
Definition: VehicleMovementComponent.cpp:193
virtual FSavedMovePtr AllocateNewMove() override
Allocates a new copy of our custom saved move.
Definition: VehicleMovementComponent.cpp:198
FNetworkPredictionData_Client_Character Super
Definition: VehicleMovementComponent.h:135
Definition: VehicleMovementComponent.h:101
uint8 bSavedWantsSteerRight
Definition: VehicleMovementComponent.h:126
uint8 bSavedWantsToBoostUpwards
Definition: VehicleMovementComponent.h:127
uint8 bSavedWantsSteerLeft
Definition: VehicleMovementComponent.h:125
uint8 bSavedWantsToBoost
Definition: VehicleMovementComponent.h:124
FSavedMove_Character Super
Definition: VehicleMovementComponent.h:104
Definition: VehicleMovementComponent.h:16
uint8 bWantsSteerRight
Definition: VehicleMovementComponent.h:45
uint8 bWantsToBoostUpwards
Definition: VehicleMovementComponent.h:44
FRotator TargetRotation
Definition: VehicleMovementComponent.h:64
uint8 bWantsSteerLeft
Definition: VehicleMovementComponent.h:46
uint8 bWantsToBoost
Definition: VehicleMovementComponent.h:43