Space Plunder
Loading...
Searching...
No Matches
RecoilAnimationComponent.h
Go to the documentation of this file.
1// Designed by Hitman's Store, 2023
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Components/ActorComponent.h"
7#include "Components/TimelineComponent.h"
8#include "Net/UnrealNetwork.h"
9#include "Kismet/KismetMathLibrary.h"
10#include "RecoilData.h"
11#include "RecoilAnimationComponent.generated.h"
12
13class UStoredData;
14class UUserWidget;
15
16DECLARE_LOG_CATEGORY_EXTERN(LogRecoilAnimation, Log, All);
17
18// DECLARE_DELEGATE(FDoTransition);
19// DECLARE_DELEGATE_RetVal(bool, FCheckCondition);
20
21
22UCLASS(ClassGroup=(RecoilAnimation), meta=(BlueprintSpawnableComponent))
23class RECOILANIMATION_API URecoilAnimationComponent : public UActorComponent
24{
25 GENERATED_BODY()
26
27public:
28 URecoilAnimationComponent();
29
30 virtual void TickComponent(float DeltaTime, ELevelTick TickType,
31 FActorComponentTickFunction* ThisTickFunction) override;
32
33 UFUNCTION(BlueprintCallable, Category = "Essentials")
34 void Init(const FRecoilAnimData Data, const float Rate = 0.0f, const int Bursts = 0);
35
36 UFUNCTION(BlueprintCallable, Category = "Essentials")
37 void Play();
38
39 UFUNCTION(BlueprintCallable, Category = "Essentials")
40 void Stop();
41
42 FORCEINLINE FTransform GetOutput() const { return FTransform(OutRot, OutLoc); };
43
44 UFUNCTION(BlueprintCallable, Category = "Essentials")
45 void SetFireMode(EFireMode_PRAS NewMode);
46
47 UFUNCTION(BlueprintCallable, Category = "Essentials")
48 void SetAimingStatus(bool bStatus);
49
50 UFUNCTION(BlueprintCallable, Category = "Essentials")
51 void SaveData();
52
53 UFUNCTION(BlueprintCallable, Category = "Essentials")
54 void ScaleInput(FInputScale_PRAS NewScale);
55
56 UFUNCTION(BlueprintCallable, Category = "Essentials")
57 void UnscaleInput(FInputScale_PRAS NewScale);
58
59 UFUNCTION(BlueprintCallable, Category = "Essentials")
60 void ResetInputScale();
61
62 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Debug", meta=(DevelopmentOnly))
63 FORCEINLINE EFireMode_PRAS GetFireMode() const { return FireMode; };
64
66 UFUNCTION(BlueprintCallable, Category = "Debug")
67 float GetDelta() const;
68
69 UFUNCTION(BlueprintCallable, Category = "Debug", meta=(DevelopmentOnly))
70 void Simulate(bool bStartSim);
71
72 UFUNCTION(BlueprintCallable, Category = "Debug", meta=(DevelopmentOnly))
73 void ShowUI();
74
75 UFUNCTION(BlueprintCallable, Category = "Debug", meta=(DevelopmentOnly))
76 void HideUI();
77
78 void AddEvent(float Time, FOnTimelineEvent Event);
79
80 UPROPERTY(BlueprintReadWrite, Category = "UI")
81 FMuteAxis MuteRot;
82
83 UPROPERTY(BlueprintReadWrite, Category = "UI")
84 FMuteAxis MuteLoc;
85
86 UPROPERTY(BlueprintReadWrite, Replicated, Category = "Recoil Animation")
87 FRecoilAnimData AnimData;
88
89 UPROPERTY(BlueprintReadWrite, Replicated, Category = "Recoil Animation")
90 FInputScale_PRAS InputScale;
91
92protected:
93 virtual void BeginPlay() override;
94
95private:
96 UFUNCTION()
97 void AnimationUpdate(FVector VectorAlpha);
98
99 UFUNCTION()
100 void CalculateTargetData();
101
109 double CorrectStart(double& Last, const double Current, bool& bStartRest, double& StartVal);
110
112 FORCEINLINE double GLerp(double A, double B, double Alpha, double DeltaTime)
113 {
114 return FMath::Lerp(A, B, 1 - FMath::Exp(-Alpha * DeltaTime));
115 };
116
117 FVector GLerp(FVector A, FVector B, FVector Alpha, float DeltaTime);
118
119 FRotator GLerp(FRotator A, FRotator B, FVector Alpha, float DeltaTime);
120
121 void SetupStateMachine();
122
123 void SetSimulationTimer(float SemiDelay);
124
129 double GetAngularRecoil(const FVector4 RecoilProfile);
130
132 void CorrectAlpha(const UCurveVector* Rotation, const UCurveVector* Location, const float TimeCorrection);
133
135 void SetupTransition(FRotator StartRot, FVector StartLoc, UCurveVector* Rot, UCurveVector* Loc);
136
137 void SetupComponent();
138
139 void TickAdvancedSolver(float DeltaTime);
140
142 float DampSpring(float Current, FFloatSpringState& SpringState, float Stiffness, float Damping, float DeltaTime);
143
144 void ApplySmoothing(float DeltaTime);
145 void ApplyNoise(FTransform& Finalized, float DeltaTime);
146 void ApplyPushback(FTransform& Finalized, float DeltaTime);
147 void ApplyProgression(FTransform& Finalized, float DeltaTime);
148
149 double GetNonZero(double OldValue, double NewValue) const
150 {
151 if(FMath::IsNearlyZero(NewValue))
152 {
153 return OldValue;
154 }
155
156 return NewValue;
157 }
158
159 UPROPERTY(Replicated, BlueprintReadOnly, Category = "Recoil Animation Output", meta=(AllowPrivateAccess=true))
160 FRotator OutRot;
161
162 UPROPERTY(Replicated, BlueprintReadOnly, Category = "Recoil Animation Output", meta=(AllowPrivateAccess=true))
163 FVector OutLoc;
164
165 UPROPERTY(EditDefaultsOnly, Category = "UI")
166 TSubclassOf<UUserWidget> WidgetClass;
167
169 UPROPERTY()
170 UCurveVector* TempRot;
171
173 UPROPERTY()
174 UCurveVector* TempLoc;
175
176 UPROPERTY()
177 class UHelperWidget* Widget;
178
179 UPROPERTY(BlueprintReadOnly, meta=(AllowPrivateAccess=true), Category = "Essentials")
180 bool bIsAiming = false;
181
183 float LastShotTime = 0.f;
184
185 FTimerHandle TimerHandle;
186 FTimeline AnimTimeline;
187
188 /* Important
189 * 0 = X
190 * 1 = Y
191 * 2 = Z
192 */
193 FStartRest CanRestRot;
194 FStartRest CanRestLoc;
195
196 FRotator StartValRot;
197 FVector StartValLoc;
198
199 FRotator TargetRot;
200 FVector TargetLoc;
201
203 FFloatSpringState PitchState;
204 FFloatSpringState RollState;
205 FFloatSpringState KickState;
206
208 FOnTimelineVector ProgressFunction;
209
211 bool bSim;
212
214 TEnumAsByte<EFireMode_PRAS> FireMode;
215
217 float FireRate;
218
220 int BurstAmount;
221
223 int BurstCounter;
224
226 TArray<FAnimState_PRAS> StateMachine;
227 uint8 CurrentStateIndex = 0;
228
230 FRotator RawOutRot;
231 FVector RawOutLoc;
232
234 bool bEnableSmoothing = false;
235
237 bool bAnimActive = true;
238
239 FVector2D Noise2DTarget = FVector2D::ZeroVector;
240 FVector2D Noise2DCurrent = FVector2D::ZeroVector;
241 FVector2D NoiseSpeed = FVector2D::ZeroVector;
242
243 double PushbackTarget = 0;
244 double PushbackCurrent = 0;
245 double PushbackOut = 0;
246 double PushbackSpeed = 0;
247
248 FRotator LerpedRot;
249 FVector LerpedLoc;
250
251 FVector2D PitchProgress = FVector2D::ZeroVector;
252 FVector2D ZProgress = FVector2D::ZeroVector;
253 double PitchProgressSpeed = 0;
254 double ZProgressSpeed = 0;
255};
UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent)) class CHATSYSTEM_API UChatSystemComponent
Definition ChatSystemComponent.h:13
DECLARE_LOG_CATEGORY_EXTERN(LogRecoilAnimation, Log, All)
EFireMode_PRAS
Definition RecoilData.h:24
Definition RecoilAnimation.Build.cs:6
Definition HelperWidget.h:12
Definition StoredData.h:26
Definition RecoilData.h:98
Definition RecoilData.h:113
Definition RecoilData.h:67
Definition RecoilData.h:33
Definition RecoilData.h:82