Space Plunder
Loading...
Searching...
No Matches
CharacterGrabberComponent.h
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
3#pragma once
4
5#include "CoreMinimal.h"
7// #include "Data/InteractionData.h"
8#include "CharacterGrabberComponent.generated.h"
9
10
11DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPickupActor, bool, bPickedUp);
12DECLARE_LOG_CATEGORY_EXTERN(LogGrabberComponent, Display, All);
13
14//@ TODO in Grabber,
15// Replicated = Mostly Complete
16// Zoom not Replicated
17// Rotation Needs to be completed,
18// Snapping to be completed, Check out Synty Project for Snapping
19//UE5_ALSv4_Synty
20// Items should check to see what "type" the object they're going to stick to is.
21// e.g. Huge box can't attach to tiny Gun.
22// if we're in Rotation Mode - should player be able to move there mouse/Stick, or only rotate item
23
24
25UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent))
26class INTERACTION_API UCharacterGrabberComponent : public UCharacterComponent
27{
28 GENERATED_BODY()
29
30public:
31 UCharacterGrabberComponent();
32
33 UPROPERTY(BlueprintAssignable, Category="Grabber")
34 FOnPickupActor OnPickupActor;
35
36 UFUNCTION(BlueprintCallable, Category="Grabber")
37 void SetGrabbedComponent(const FVector& Location, const FRotator& Rotation) const;
38
39 void SetThrowStrength(const float Strength){ThrowStrength = Strength;};
40 UFUNCTION(BlueprintCallable, Category="Grabber")
41 UPrimitiveComponent* GetGrabbedComponent() const;
42
43 UFUNCTION(BlueprintPure, BlueprintCallable, Category="Grabber")
44 bool GetIsHoldingActor() const;
45
46 UFUNCTION(BlueprintCallable, Category="Grabber")
47 void GrabActor(const FHitResult& HitResult);
48 UFUNCTION(Server, Reliable, Category="Grabber")
49 void Server_GrabActor(const FHitResult& HitResult);
50
51 UFUNCTION(BlueprintCallable, Category="Grabber")
52 void PickupActorFromInteraction();
53
54 UFUNCTION(Server, Reliable, Category="Grabber")
55 void GrabTick();
56
57 UFUNCTION(Server, Reliable, BlueprintCallable, Category="Grabber")
58 void Server_DropActor();
59 UFUNCTION(BlueprintCallable, Category="Grabber")
60 void DropActor();
61
62 UFUNCTION(Server, Reliable, BlueprintCallable, Category="Grabber")
63 void Server_ThrowActor(const float ForceMultiplier = 1.0f);
64 UFUNCTION(BlueprintCallable, Category="Grabber")
65 void ThrowActor(const float ForceMultiplier = 1.0f);
66
67 UFUNCTION(BlueprintCallable, Category="Grabber")
68 void SetGrabDistance(const float Distance);
69 UFUNCTION(BlueprintPure, BlueprintCallable, Category="Grabber")
70 float GetGrabDistance()const {return GrabDistance;};
71
72 //~ Object Rotation ~//
73 UFUNCTION(BlueprintCallable, Category="Grabber")
74 void RotateObjectXAxis(const float Value);
75 UFUNCTION(BlueprintCallable, Category="Grabber")
76 void RotateObjectYAxis(const float Value);
77 // UFUNCTION(BlueprintCallable, Category="Grabber")
78 // void ToggleRotationMode();
79 UFUNCTION(BlueprintCallable, Category="Grabber")
80 void SetGrabberRotationMode(const bool bTurnOn);
81
82 UFUNCTION(BlueprintCallable, Category="Grabber")
83 void ResetRotation();
84 //~ Object Zoom ~//
85 UFUNCTION(BlueprintCallable, Category="Grabber")
86 void ZoomObject(const float Value);
87 UFUNCTION(Server, Reliable, Category="Grabber")
88 void Server_ZoomObject(const float Value);
89
90 UFUNCTION(BlueprintCallable, Category="Grabber")
91 bool GetIsInRotationMode() const {return bRotationMode;};
92
93 FVector GetTargetLocation() const {return TargetLocation;};
94 FVector GetAttachPointLocation() const
95 {
96 if(IsActive() == false){return FVector::ZeroVector;}
97 if(AttachPoint == nullptr){LogDebugError("GetAttachPointLocation, AttachPoint");return FVector::ZeroVector;}
98 return AttachPoint->GetComponentLocation();
99 }
100
101protected:
102 virtual void BeginPlay() override;
103 virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
104 virtual void ComponentSetupComplete() override;
105 virtual void ComponentDeactivated(UActorComponent* Component) override;
106
107 UFUNCTION(Server, Reliable, Category="Grabber")
108 void Server_PickupActor(const FName BoneName, const FVector Location, const FRotator Rotation);
109 UFUNCTION(BlueprintCallable, Category="Grabber")
110 void PickupActor(const FName BoneName, const FVector Location, const FRotator Rotation);
111
112
113 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Debugging")
114 bool bLogTick = false;
115 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Debugging")
116 bool bSetRotation = true;
117 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Debugging")
118 bool bUseNormalTick = true;
119 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Debugging")
120 bool bAddStartRotation = true;
121 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Debugging")
122 bool bSetRotationZero = true;
123 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Debugging")
124 bool bOverrideMass = false;
125 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Debugging", meta=(EditCondition=bOverrideMass))
126 float NewMass = 0.5f;
127 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Debugging")
128 bool bShowTraceLocations = false;
129
130 //- Additional/Less distance for Grabbing //
131 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|General")
132 float GrabDistanceAddition= -30.0f;
133 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|General")
134 float GrabLocationOffset = 120.0f;
135 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|General")
136 float GrabUpdateTick = 0.01f;
137 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|General")
138 bool bUseCameraLocation = true;
139 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|General")
140 bool bUsePlayerOffset = true;
141 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|General")
142 bool bUsePlayerRotation = true;
143
144
145
146 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Physics")
147 float LinearDamping = 200.0f;
148 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Physics")
149 float LinearStiffness = 1750.0f;
150 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Physics")
151 float AngularDamping = 500.0f;
152 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Physics")
153 float AngularStiffness = 1500.0f;
154 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Physics")
155 float InterpolationSpeed = 1000.0f;
156
157
158 //~ Zoom Vars ~//
159 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Zoom")
160 float ZoomSpeed = 10.0f;
161 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Zoom")
162 float ZoomClampMin = 50.0f;
163 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Zoom")
164 float ZoomClampMax = 150.0f;
165 UPROPERTY(Replicated, EditAnywhere, BlueprintReadOnly, Category="Grabber|Zoom")
166 float ZoomValue = 150.0f;
167 float ZoomValueDefault = 0.0f;
168
169 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Rotate")
170 bool bUseRotateLerp = false;
171 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Rotate", meta=(ClampMin=0.0f, ClampMax=1.0f))
172 float SmoothAutoRotation = 0.4;
173 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Rotate")
174 float RotationModeSensitivity = 150.0f;
175
176 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Rotate")
177 bool bYRotationDisabled = false;
178 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Rotate")
179 bool bXRotationDisabled = false;
180
181
182 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Snapping")
183 TEnumAsByte<ECollisionChannel> SnapTraceChannel;
184 // UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Grabber|Snapping")
185 // float SnapTraceLengthMultiplier = 1.0f;
186
187private:
188 void ResetValues();
189 FVector GetThrowForce(const float Multiplier) const;
190 FRotator GetRotation() const;
191 FVector GetLocation() const;
192
193 UFUNCTION(Server, Reliable, Category="Grabber")
194 void Server_SetGrabDistance(const float Distance);
195
196 void SnapLineTrace();
197 void DrawSnapStatus(const FVector& Location) const;
198
199
200 bool GetPhysicsComponent(const AActor* Actor);
201 bool GetPhysicsActor(AActor* Actor);
202
203 UFUNCTION()
204 void OnRep_CanSnap();
205
206
207 UPROPERTY(Replicated, VisibleAnywhere, Category="Grabber|Status")
208 bool bHoldingActor = false;
209 UPROPERTY(Replicated, VisibleAnywhere, Category="Grabber|Status")
210 bool bRotationMode = false;
211 UPROPERTY(Replicated, VisibleAnywhere, Category="Grabber|Status")
212 float GrabDistance = 500.0f;
213 UPROPERTY(ReplicatedUsing=OnRep_CanSnap, VisibleAnywhere, Category="Grabber|Status")
214 bool bCanSnap = false;
215
216 class IPhysicsPickup* PhysicsPickup = nullptr;
217
218 UPROPERTY(VisibleAnywhere, Category="Grabber|Status")
219 FVector TargetLocation = FVector::ZeroVector;
220 UPROPERTY(VisibleAnywhere, Category="Grabber|Status")
221 FName TargetBone = NAME_None;
222 UPROPERTY(VisibleAnywhere, Category="Grabber|Status")
223 FRotator CurrentHeldRotation = FRotator::ZeroRotator;
224 UPROPERTY(VisibleAnywhere, Category="Grabber|Status")
225 FVector LastHeldLocation = FVector::ZeroVector;
227 UPROPERTY(VisibleAnywhere, Category="Grabber|Status")
228 float TraceDistanceMin = 10.0f;
229
230 FRotator PendingRotationDelta;
231 float RotationInputBufferTime = 0.0f;
232 const float RotationApplyRate = 1.0f / 20.0f; // 20 times/sec (50ms)
233
234 UFUNCTION(Server, Unreliable)
235 void Server_ApplyRotationDelta(FRotator Delta);
236 void ApplyRotationDelta(const FRotator& Delta);
237
238 UPROPERTY(Replicated, VisibleAnywhere, Category="Grabber|Status|Components")
239 class UPrimitiveComponent* TargetComponent = nullptr;
240 UPROPERTY(VisibleAnywhere, Category="Grabber|Status|Components")
241 class UPrimitiveComponent* TargetComponentAttach = nullptr;
242
243
244 UPROPERTY(Replicated)
245 class UPhysicsHandleComponent* PhysicsHandleComponent;
246 UPROPERTY(Replicated)
247 class USceneComponent* AttachPoint = nullptr;
248
249 float ThrowStrength = 500.0f;
250
251 UPROPERTY()
252 FHitResult LastHitResult;
253
254 FTimerHandle GrabTickTimerHandle;
255};
256
257
DECLARE_LOG_CATEGORY_EXTERN(LogGrabberComponent, Display, All)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPickupActor, bool, bPickedUp)
UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent)) class CHATSYSTEM_API UChatSystemComponent
Definition ChatSystemComponent.h:13
Definition PhysicsPickup.h:21
Represents a character component that can be added to an actor.