A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
GS_Melee.h
Go to the documentation of this file.
1#pragma once
2
3#include "CoreMinimal.h"
4#include "Engine/Engine.h"
5#include "VRGripScriptBase.h"
6#include "GameFramework/WorldSettings.h"
8#include "GS_Melee.generated.h"
9
10#if PHYSICS_INTERFACE_PHYSX
11#include "PhysXPublic.h"
12#endif // WITH_PHYSX
13
14
15
16// The type of melee hit zone we are
17UENUM(BlueprintType)
18enum class EVRMeleeZoneType : uint8
19{
20 // This zone is only valid for stabs
22
23 // This zone is only valid for hits
25
26 // This zone is valid for both stabs and hits
27 VRPMELLE_ZONETYPE_StabAndHit UMETA(DisplayName = "StabAndHit")
28
29};
30
31// The type of COM selection to use
32UENUM(BlueprintType)
33enum class EVRMeleeComType : uint8
34{
35 // Does not set COM
36 VRPMELEECOM_Normal UMETA(DisplayName = "Normal"),
37
38 // Sets COM to between hands
39 VRPMELEECOM_BetweenHands UMETA(DisplayName = "BetweenHands"),
40
41 // Uses the primary hand as com location
42 VRPMELEECOM_PrimaryHand UMETA(DisplayName = "PrimaryHand")
43};
44
45// The type of primary hand selection to use
46UENUM(BlueprintType)
47enum class EVRMeleePrimaryHandType : uint8
48{
49 // Uses the rearmost hand as the primary hand
50 VRPHAND_Rear UMETA(DisplayName = "Rear"),
51
52 // Uses the foremost hand as the primary hand
53 VRPHAND_Front UMETA(DisplayName = "Front"),
54
55 // Uses the first slotted hand as the primary hand
56 // If neither are slotted then its first come first serve and both hannds load the secondary settings
57 VRPHAND_Slotted UMETA(DisplayName = "Slotted")
58};
59
60// A Lodge component data struct
61USTRUCT(BlueprintType, Category = "Lodging")
62struct VREXPANSIONPLUGIN_API FBPHitSurfaceProperties
63{
64 GENERATED_BODY()
65public:
66
67 // Does this surface type allow penetration
68 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Surface Property")
69 bool bSurfaceAllowsPenetration;
70
71 // Scaler to damage applied from hitting this surface with blunt damage
72 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Surface Property")
73 float BluntDamageScaler;
75 // Scaler to damage applied from hitting this surface with sharp damage
76 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Surface Property")
77 float SharpDamageScaler;
78
79 // Alters the stab velocity to let you make it harder or easier to stab this surface
80 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Surface Property")
81 float StabVelocityScaler;
82
83 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Surface Property")
84 TEnumAsByte<EPhysicalSurface> SurfaceType;
87 {
88 // Default to true on this
89 bSurfaceAllowsPenetration = true;
90 BluntDamageScaler = 1.f;
91 SharpDamageScaler = 1.f;
92 StabVelocityScaler = 1.f;
93 SurfaceType = EPhysicalSurface::SurfaceType_Default;
94 }
95};
96
97// A Lodge component data struct
98USTRUCT(BlueprintType, Category = "Lodging")
99struct VREXPANSIONPLUGIN_API FBPLodgeComponentInfo
100{
101 GENERATED_BODY()
102public:
103
104 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LodgeComponentInfo")
105 FName ComponentName;
106
107 // Type of collision zone we are
108 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LodgeComponentInfo")
110
111 // If true than we will calculate hit impulse off of its total value and not just off of it axially aligned to the forward of this body
112 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LodgeComponentInfo")
113 bool bIgnoreForwardVectorForHitImpulse;
114
115 // For end users to provide a base damage per zone if they want
116 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LodgeComponentInfo")
117 float DamageScaler;
119 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LodgeComponentInfo")
120 float PenetrationDepth;
121
122 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LodgeComponentInfo")
123 bool bAllowPenetrationInReverseAsWell;
124
125 // This is the impulse velocity (along forward axis of component) required to throw an OnPenetrated event from a PenetrationNotifierComponent
126 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
127 float PenetrationVelocity;
128
129 // This is the impulse velocity required to throw an OnHit event from a PenetrationNotifierComponent (If a stab didn't take place)
130 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
131 float MinimumHitVelocity;
132
133 // The acceptable range of the dot product of the forward vector and the impact normal to define a valid facing
134 // Subtracted from the 1.0f forward facing value
135 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
136 float AcceptableForwardProductRange;
137
138 // The acceptable range of the dot product of the forward vector and the impact normal to define a valid facing
139 // Subtracted from the 1.0f forward facing value
140 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
141 float AcceptableForwardProductRangeForHits;
142
145 ComponentName = NAME_None;
147 bIgnoreForwardVectorForHitImpulse = false;
148 DamageScaler = 0.f;
149 PenetrationDepth = 100.f;
150 bAllowPenetrationInReverseAsWell = false;
151 PenetrationVelocity = 8000.f;
152 MinimumHitVelocity = 1000.f;
153 AcceptableForwardProductRange = 0.1f;
154 AcceptableForwardProductRangeForHits = 0.1f;
155 }
156
157 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "LodgeComponentInfo")
158 TWeakObjectPtr<UPrimitiveComponent> TargetComponent;
159
160 FORCEINLINE bool operator==(const FName& Other) const
161 {
162 return (ComponentName == Other);
163 }
164
165};
166
167
168// Event thrown when we the melee weapon becomes lodged
169DECLARE_DYNAMIC_MULTICAST_DELEGATE_SevenParams(FVROnMeleeShouldLodgeSignature, FBPLodgeComponentInfo, LogComponent, AActor *, OtherActor, UPrimitiveComponent *, OtherComp, ECollisionChannel, OtherCompCollisionChannel, FBPHitSurfaceProperties, HitSurfaceProperties, FVector, NormalImpulse, const FHitResult&, Hit);
170DECLARE_DYNAMIC_MULTICAST_DELEGATE_SevenParams(FVROnMeleeOnHit, FBPLodgeComponentInfo, LogComponent, AActor*, OtherActor, UPrimitiveComponent*, OtherComp, ECollisionChannel, OtherCompCollisionChannel, FBPHitSurfaceProperties, HitSurfaceProperties, FVector, NormalImpulse, const FHitResult&, Hit);
171DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FVROnMeleeInvalidHitSignature, AActor*, OtherActor, UPrimitiveComponent*, OtherComp, FVector, NormalImpulse, const FHitResult&, Hit);
172
177UCLASS(NotBlueprintable, ClassGroup = (VRExpansionPlugin), hideCategories = TickSettings)
178class VREXPANSIONPLUGIN_API UGS_Melee : public UGS_Default
179{
180 GENERATED_BODY()
181public:
183 UGS_Melee(const FObjectInitializer& ObjectInitializer);
184
185 UFUNCTION()
186 virtual void OnLodgeHitCallback(AActor* SelfActor, AActor* OtherActor, FVector NormalImpulse, const FHitResult& Hit);
187
188 UFUNCTION(BlueprintCallable, Category = "Weapon Settings")
189 void SetIsLodged(bool IsLodged, UPrimitiveComponent * LodgeComponent)
191 bIsLodged = IsLodged;
192 LodgedComponent = LodgeComponent;
193 }
194
195 bool bIsLodged;
196 TWeakObjectPtr<UPrimitiveComponent> LodgedComponent;
197
198 //virtual void Tick(float DeltaTime) override;
199
200 // Thrown if we should lodge into a hit object
201 UPROPERTY(BlueprintAssignable, Category = "Melee|Lodging")
202 FVROnMeleeShouldLodgeSignature OnShouldLodgeInObject;
203
204 // Thrown if we hit something we can damage
205 UPROPERTY(BlueprintAssignable, Category = "Melee|Hit")
206 FVROnMeleeOnHit OnMeleeHit;
208 // Fired when a hit is invalid (hit something that isn't flagged for damage or stabbing or was below the damage or stab threshold)
209 UPROPERTY(BlueprintAssignable, Category = "Melee|Hit")
210 FVROnMeleeInvalidHitSignature OnMeleeInvalidHit;
211
212 // Always tick for penetration
213 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Melee|Lodging")
214 bool bAlwaysTickPenetration;
215
216 // Only penetrate with two hands on the weapon
217 // Mostly for very large weapons
218 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Melee|Lodging")
219 bool bOnlyPenetrateWithTwoHands;
220
221 // A list of surface types that allow penetration and their properties
222 // If empty then the script will use the global settings, if filled with anything then it will override the global settings
223 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Melee|Lodging")
224 TArray<FBPHitSurfaceProperties> OverrideMeleeSurfaceSettings;
225
226// FVector RollingVelocityAverage;
227 //FVector RollingAngVelocityAverage;
228
229 // The name of the component that is used to orient the weapon along its primary axis
230 // If it does not exist then the weapon is assumed to be X+ facing.
231 // Also used to perform some calculations, make sure it is parented to the gripped object (root component for actors).
232 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
233 FName WeaponRootOrientationComponent;
234 FTransform OrientationComponentRelativeFacing;
235
236 // UpdateHand location on the shaft in the X axis
237 // If primary hand is false then it will do the secondary hand
238 // World location is of the pivot generally, I have it passing in so people can snap
239 // LocDifference returns the relative distance of the change in position (or zero if there was none).
240 UFUNCTION(BlueprintCallable, Category = "Weapon Settings")
241 void UpdateHandPosition(FBPGripPair HandPair, FVector HandWorldPosition, FVector & LocDifference);
242
243 // UpdateHand location and rotation on the shaft in the X axis
244 // If primary hand is false then it will do the secondary hand
245 // World location is of the pivot generally, I have it passing in so people can snap
246 // LocDifference returns the relative distance of the change in position (or zero if there was none).
247 UFUNCTION(BlueprintCallable, Category = "Weapon Settings")
248 void UpdateHandPositionAndRotation(FBPGripPair HandPair, FTransform HandWorldTransform, FVector& LocDifference, float& RotDifference, bool bUpdateLocation = true, bool bUpdateRotation = true);
251 // This is a built list of components that act as penetration notifiers, they will have their OnHit bound too and we will handle penetration logic
252 // off of it.
253 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
254 TArray<FBPLodgeComponentInfo> PenetrationNotifierComponents;
255
256 bool bCheckLodge;
257 bool bIsHeld;
258
259 FVector LastRelativePos;
260 FVector RelativeBetweenGripsCenterPos;
261
262 // When true, will auto set the primary and secondary hands by the WeaponRootOrientationComponents X Axis distance.
263 // Smallest value along the X Axis will be considered the primary hand.
264 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
265 bool bAutoSetPrimaryAndSecondaryHands;
266
267 // If we couldn't decide on a true valid primary hand then this will be false and we will load secondary settings for both
268 bool bHasValidPrimaryHand;
269
270 UFUNCTION(BlueprintCallable, Category = "Weapon Settings")
271 void SetPrimaryAndSecondaryHands(FBPGripPair & PrimaryGrip, FBPGripPair & SecondaryGrip);
272
273 // Which method of primary hand to select
274 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
275 EVRMeleePrimaryHandType PrimaryHandSelectionType;
277 UPROPERTY(BlueprintReadOnly, Category = "Weapon Settings")
278 FBPGripPair PrimaryHand;
279
280 UPROPERTY(BlueprintReadOnly, Category = "Weapon Settings")
281 FBPGripPair SecondaryHand;
283 // If true we will use the primary hands grip settings when we only have one hand gripping instead of the objects VRGripInterfaces settings
284 UPROPERTY(BlueprintReadOnly, Category = "Weapon Settings")
285 bool bUsePrimaryHandSettingsWithOneHand;
286
287 // To select the type of com setting to use
288 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
289 EVRMeleeComType COMType;
290
291 FTransform ObjectRelativeGripCenter;
293 void SetComBetweenHands(UGripMotionControllerComponent* GrippingController, FBPActorPhysicsHandleInformation * HandleInfo);
294
295
296 // Grip settings to use on the primary hand when multiple grips are active
297 // Falls back to the standard grip settings when only one grip is active
298 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
299 FBPAdvancedPhysicsHandleSettings PrimaryHandPhysicsSettings;
300
301 // Grip settings to use on the secondary hand when multiple grips are active
302 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
303 FBPAdvancedPhysicsHandleSettings SecondaryHandPhysicsSettings;
304
305
306 void UpdateDualHandInfo();
307
308 virtual void HandlePostPhysicsHandle(UGripMotionControllerComponent* GrippingController, FBPActorPhysicsHandleInformation* HandleInfo) override;
309 virtual void HandlePrePhysicsHandle(UGripMotionControllerComponent* GrippingController, const FBPActorGripInformation &GripInfo, FBPActorPhysicsHandleInformation* HandleInfo, FTransform& KinPose) override;
310 virtual void OnBeginPlay_Implementation(UObject* CallingOwner) override;
311 virtual void OnEndPlay_Implementation(const EEndPlayReason::Type EndPlayReason) override;
312 virtual void OnSecondaryGrip_Implementation(UGripMotionControllerComponent* Controller, USceneComponent* SecondaryGripComponent, const FBPActorGripInformation& GripInformation) override;
313
314 virtual void OnGrip_Implementation(UGripMotionControllerComponent* GrippingController, const FBPActorGripInformation& GripInformation) override;
315
316 virtual void OnGripRelease_Implementation(UGripMotionControllerComponent* ReleasingController, const FBPActorGripInformation& GripInformation, bool bWasSocketed = false) override;
317
318 virtual bool Wants_DenyTeleport_Implementation(UGripMotionControllerComponent* Controller) override;
319
320 //virtual void BeginPlay_Implementation() override;
321 virtual bool GetWorldTransform_Implementation(UGripMotionControllerComponent * GrippingController, float DeltaTime, FTransform & WorldTransform, const FTransform &ParentTransform, FBPActorGripInformation &Grip, AActor * actor, UPrimitiveComponent * root, bool bRootHasInterface, bool bActorHasInterface, bool bIsForTeleport) override;
322
324};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FVROnMeleeInvalidHitSignature, AActor *, OtherActor, UPrimitiveComponent *, OtherComp, FVector, NormalImpulse, const FHitResult &, Hit)
EVRMeleeZoneType
UENUM(BlueprintType)
Definition GS_Melee.h:22
DECLARE_DYNAMIC_MULTICAST_DELEGATE_SevenParams(FVROnMeleeShouldLodgeSignature, FBPLodgeComponentInfo, LogComponent, AActor *, OtherActor, UPrimitiveComponent *, OtherComp, ECollisionChannel, OtherCompCollisionChannel, FBPHitSurfaceProperties, HitSurfaceProperties, FVector, NormalImpulse, const FHitResult &, Hit)
EVRMeleePrimaryHandType
UENUM(BlueprintType)
Definition GS_Melee.h:57
EVRMeleeComType
UENUM(BlueprintType)
Definition GS_Melee.h:40
UCLASS(NotBlueprintable, ClassGroup = (VRExpansionPlugin))
Definition GS_Default.h:17
UCLASS(NotBlueprintable, ClassGroup = (VRExpansionPlugin), hideCategories = TickSettings)
Definition GS_Melee.h:261
FTransform OrientationComponentRelativeFacing
Definition GS_Melee.h:346
bool bIsLodged
Definition GS_Melee.h:282
EVRMeleePrimaryHandType PrimaryHandSelectionType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
Definition GS_Melee.h:408
TArray< FBPLodgeComponentInfo > PenetrationNotifierComponents
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
Definition GS_Melee.h:376
bool bIsHeld
Definition GS_Melee.h:379
bool bOnlyPenetrateWithTwoHands
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Melee|Lodging")
Definition GS_Melee.h:323
bool bUsePrimaryHandSettingsWithOneHand
UPROPERTY(BlueprintReadOnly, Category = "Weapon Settings")
Definition GS_Melee.h:427
FVector RelativeBetweenGripsCenterPos
Definition GS_Melee.h:382
bool bHasValidPrimaryHand
Definition GS_Melee.h:394
FVROnMeleeOnHit OnMeleeHit
UPROPERTY(BlueprintAssignable, Category = "Melee|Hit")
Definition GS_Melee.h:299
void SetIsLodged(bool IsLodged, UPrimitiveComponent *LodgeComponent)
UFUNCTION(BlueprintCallable, Category = "Weapon Settings")
Definition GS_Melee.h:276
FVROnMeleeInvalidHitSignature OnMeleeInvalidHit
UPROPERTY(BlueprintAssignable, Category = "Melee|Hit")
Definition GS_Melee.h:306
bool bCheckLodge
Definition GS_Melee.h:378
EVRMeleeComType COMType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
Definition GS_Melee.h:435
FBPGripPair SecondaryHand
UPROPERTY(BlueprintReadOnly, Category = "Weapon Settings")
Definition GS_Melee.h:420
FVector LastRelativePos
Definition GS_Melee.h:381
FBPAdvancedPhysicsHandleSettings SecondaryHandPhysicsSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
Definition GS_Melee.h:457
FTransform ObjectRelativeGripCenter
Definition GS_Melee.h:437
TWeakObjectPtr< UPrimitiveComponent > LodgedComponent
Definition GS_Melee.h:283
FBPGripPair PrimaryHand
UPROPERTY(BlueprintReadOnly, Category = "Weapon Settings")
Definition GS_Melee.h:414
FName WeaponRootOrientationComponent
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
Definition GS_Melee.h:345
FBPAdvancedPhysicsHandleSettings PrimaryHandPhysicsSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
Definition GS_Melee.h:449
FVROnMeleeShouldLodgeSignature OnShouldLodgeInObject
UPROPERTY(BlueprintAssignable, Category = "Melee|Lodging")
Definition GS_Melee.h:292
bool bAlwaysTickPenetration
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Melee|Lodging")
Definition GS_Melee.h:314
bool bAutoSetPrimaryAndSecondaryHands
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
Definition GS_Melee.h:391
TArray< FBPHitSurfaceProperties > OverrideMeleeSurfaceSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Melee|Lodging")
Definition GS_Melee.h:332
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController)
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "Lodging")
Definition GS_Melee.h:75
bool bSurfaceAllowsPenetration
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Surface Property")
Definition GS_Melee.h:85
float SharpDamageScaler
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Surface Property")
Definition GS_Melee.h:101
TEnumAsByte< EPhysicalSurface > SurfaceType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Surface Property")
Definition GS_Melee.h:116
float StabVelocityScaler
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Surface Property")
Definition GS_Melee.h:109
float BluntDamageScaler
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Surface Property")
Definition GS_Melee.h:93
USTRUCT(BlueprintType, Category = "Lodging")
Definition GS_Melee.h:135
FName ComponentName
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LodgeComponentInfo")
Definition GS_Melee.h:144
bool bIgnoreForwardVectorForHitImpulse
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LodgeComponentInfo")
Definition GS_Melee.h:160
float AcceptableForwardProductRange
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
Definition GS_Melee.h:207
float MinimumHitVelocity
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
Definition GS_Melee.h:198
bool bAllowPenetrationInReverseAsWell
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LodgeComponentInfo")
Definition GS_Melee.h:182
FORCEINLINE bool operator==(const FName &Other) const
Definition GS_Melee.h:239
float DamageScaler
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LodgeComponentInfo")
Definition GS_Melee.h:168
float PenetrationVelocity
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
Definition GS_Melee.h:190
EVRMeleeZoneType ZoneType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LodgeComponentInfo")
Definition GS_Melee.h:152
float AcceptableForwardProductRangeForHits
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
Definition GS_Melee.h:216
TWeakObjectPtr< UPrimitiveComponent > TargetComponent
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "LodgeComponentInfo")
Definition GS_Melee.h:237
float PenetrationDepth
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LodgeComponentInfo")
Definition GS_Melee.h:175