A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
VRMountComponent.h
Go to the documentation of this file.
1
2#pragma once
3
4#include "CoreMinimal.h"
6#include "MotionControllerComponent.h"
7#include "VRGripInterface.h"
8#include "GameplayTagContainer.h"
9#include "GameplayTagAssetInterface.h"
11#include "PhysicsEngine/ConstraintInstance.h"
12#include "Components/StaticMeshComponent.h"
13
14#include "PhysicsPublic.h"
15
16#if WITH_PHYSX
17//#include "PhysXSupport.h"
18#endif // WITH_PHYSX
19
20
21#include "VRMountComponent.generated.h"
22
23
24UENUM(Blueprintable)
25enum class EVRInteractibleMountAxis : uint8
26{
29};
30
31// A mounted lever/interactible implementation - Created by SpaceHarry - Merged into the plugin 01/29/2018
32UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = (VRExpansionPlugin))
33class VREXPANSIONPLUGIN_API UVRMountComponent : public UStaticMeshComponent, public IVRGripInterface, public IGameplayTagAssetInterface
34{
35 GENERATED_BODY()
36
37public:
38 UVRMountComponent(const FObjectInitializer& ObjectInitializer);
40
42
43
44 // Rotation axis to use, XY is combined X and Y, only LerpToZero and PositiveLimits work with this mode
45 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRMountComponent")
46 EVRInteractibleMountAxis MountRotationAxis;
47
48 // Resetting the initial transform here so that it comes in prior to BeginPlay and save loading.
49 virtual void OnRegister() override;
50
51 FTransform InitialRelativeTransform;
52 FVector InitialInteractorLocation;
53 FVector InitialInteractorDropLocation;
54 float InitialGripRot;
55 FQuat qRotAtGrab;
57 // If the mount is swirling around a 90 degree pitch increase this number by 0.1 steps.
58 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRMountComponent")
59 float FlipingZone;
60
61 // If the mount feels lagging behind in yaw at some point after 90 degree pitch increase this number by 0.1 steps
62 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRMountComponent")
63 float FlipReajustYawSpeed;
65 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripSettings")
66 int GripPriority;
67
68 // Sets the grip priority
69 UFUNCTION(BlueprintCallable, Category = "GripSettings")
70 void SetGripPriority(int NewGripPriority);
71
72 bool GrippedOnBack;
74 bool bIsInsideFrontFlipingZone;
75 bool bIsInsideBackFlipZone;
76 FVector CurInterpGripLoc;
77
78 float TwistDiff;
79 FVector InitialGripToForwardVec;
80 FVector InitialForwardVector;
81 FVector EntryUpXYNeg;
82 FVector EntryUpVec;
83 FVector EntryRightVec;
84
85 bool bFirstEntryToHalfFlipZone;
86 bool bLerpingOutOfFlipZone;
87 bool bIsFlipped;
89 FPlane FlipPlane;
90 FPlane ForwardPullPlane;
91 FVector LastPointOnForwardPlane;
92 FVector CurPointOnForwardPlane;
93
94 float LerpOutAlpha;
95
96 // ------------------------------------------------
97 // Gameplay tag interface
98 // ------------------------------------------------
101 virtual void GetOwnedGameplayTags(FGameplayTagContainer& TagContainer) const override
102 {
103 TagContainer = GameplayTags;
107 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "GameplayTags")
108 FGameplayTagContainer GameplayTags;
109
110 // End Gameplay Tag Interface
112 virtual void PreReplication(IRepChangedPropertyTracker & ChangedPropertyTracker) override;
113
115 // Requires bReplicates to be true for the component
116 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
117 bool bRepGameplayTags;
118
119 // Overrides the default of : true and allows for controlling it like in an actor, should be default of off normally with grippable components
120 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface|Replication")
121 bool bReplicateMovement;
122
123 virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
124 virtual void BeginPlay() override;
125
126 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
127 EGripMovementReplicationSettings MovementReplicationSetting;
128
129 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
130 float Stiffness;
131
132 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
133 float Damping;
134
135 // Distance before the object will break out of the hand, 0.0f == never will
136 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
137 float BreakDistance;
139 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripSettings")
140 float PrimarySlotRange;
141
142 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripSettings")
143 float SecondarySlotRange;
144
145 // Should we deny gripping on this object
146 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface", meta = (ScriptName = "IsDenyGripping"))
147 bool bDenyGripping;
148
149 UPROPERTY(BlueprintReadOnly, Category = "VRGripInterface", meta = (ScriptName = "IsCurrentlyHeld"))
150 bool bIsHeld; // Set on grip notify, not net serializing
151
152 UPROPERTY(BlueprintReadOnly, Category = "VRGripInterface")
153 FBPGripPair HoldingGrip; // Set on grip notify, not net serializing
154 bool bOriginalReplicatesMovement;
155
156 // Should be called after the Mount is moved post begin play
157 UFUNCTION(BlueprintCallable, Category = "VRMountComponent")
158 void ResetInitialMountLocation()
159 {
160 // Get our initial relative transform to our parent (or not if un-parented).
161 InitialRelativeTransform = this->GetRelativeTransform();
162 }
163
164 virtual void OnUnregister() override;;
165
166 // Grip interface setup
167
168 // Set up as deny instead of allow so that default allows for gripping
169 // The GripInitiator is not guaranteed to be valid, check it for validity
170 bool DenyGripping_Implementation(UGripMotionControllerComponent * GripInitiator = nullptr) override;
172 // How an interfaced object behaves when teleporting
173 EGripInterfaceTeleportBehavior TeleportBehavior_Implementation() override;
174
175 // Should this object simulate on drop
176 bool SimulateOnDrop_Implementation() override;
177
178 // Grip type to use
179 EGripCollisionType GetPrimaryGripType_Implementation(bool bIsSlot) override;
180
181 // Secondary grip type
182 ESecondaryGripType SecondaryGripType_Implementation() override;
183
184 // Define which movement repliation setting to use
185 EGripMovementReplicationSettings GripMovementReplicationType_Implementation() override;
186
187 // Define the late update setting
188 EGripLateUpdateSettings GripLateUpdateSetting_Implementation() override;
189
190 // What grip stiffness and damping to use if using a physics constraint
191 void GetGripStiffnessAndDamping_Implementation(float& GripStiffnessOut, float& GripDampingOut) override;
192
193 // Get the advanced physics settings for this grip
194 FBPAdvGripSettings AdvancedGripSettings_Implementation() override;
195
196 // What distance to break a grip at (only relevent with physics enabled grips
197 float GripBreakDistance_Implementation() override;
198
199 // Get grip slot in range
200 void ClosestGripSlotInRange_Implementation(FVector WorldLocation, bool bSecondarySlot, bool& bHadSlotInRange, FTransform& SlotWorldTransform, FName& SlotName, UGripMotionControllerComponent* CallingController = nullptr, FName OverridePrefix = NAME_None) override;
201
202 // Check if an object allows multiple grips at one time
203 bool AllowsMultipleGrips_Implementation() override;
204
205 // Returns if the object is held and if so, which controllers are holding it
206 void IsHeld_Implementation(TArray<FBPGripPair>& CurHoldingControllers, bool& bCurIsHeld) override;
208 // Sets is held, used by the plugin
209 void SetHeld_Implementation(UGripMotionControllerComponent* NewHoldingController, uint8 GripID, bool bNewIsHeld) override;
210
211 // Returns if the object wants to be socketed
212 bool RequestsSocketing_Implementation(USceneComponent*& ParentToSocketTo, FName& OptionalSocketName, FTransform_NetQuantize& RelativeTransform) override;
213
214 // Get grip scripts
215 bool GetGripScripts_Implementation(TArray<UVRGripScriptBase*>& ArrayReference) override;
216
217
218 // Events //
219
220 // Event triggered each tick on the interfaced object when gripped, can be used for custom movement or grip based logic
221 void TickGrip_Implementation(UGripMotionControllerComponent* GrippingController, const FBPActorGripInformation& GripInformation, float DeltaTime) override;
222
223 // Event triggered on the interfaced object when gripped
224 void OnGrip_Implementation(UGripMotionControllerComponent* GrippingController, const FBPActorGripInformation& GripInformation) override;
225
226 // Event triggered on the interfaced object when grip is released
227 void OnGripRelease_Implementation(UGripMotionControllerComponent* ReleasingController, const FBPActorGripInformation& GripInformation, bool bWasSocketed = false) override;
229 // Event triggered on the interfaced object when child component is gripped
230 void OnChildGrip_Implementation(UGripMotionControllerComponent* GrippingController, const FBPActorGripInformation& GripInformation) override;
231
232 // Event triggered on the interfaced object when child component is released
233 void OnChildGripRelease_Implementation(UGripMotionControllerComponent* ReleasingController, const FBPActorGripInformation& GripInformation, bool bWasSocketed = false) override;
234
235 // Event triggered on the interfaced object when secondary gripped
236 void OnSecondaryGrip_Implementation(UGripMotionControllerComponent* GripOwningController, USceneComponent* SecondaryGripComponent, const FBPActorGripInformation& GripInformation) override;
237
238 // Event triggered on the interfaced object when secondary grip is released
239 void OnSecondaryGripRelease_Implementation(UGripMotionControllerComponent* GripOwningController, USceneComponent* ReleasingSecondaryGripComponent, const FBPActorGripInformation& GripInformation) override;
240
241 // Interaction Functions
242
243 // Call to use an object
244 void OnUsed_Implementation() override;
245
246 // Call to stop using an object
247 void OnEndUsed_Implementation() override;
248
249 // Call to use an object
250 void OnSecondaryUsed_Implementation() override;
251
252 // Call to stop using an object
253 void OnEndSecondaryUsed_Implementation() override;
254
255 // Call to send an action event to the object
256 void OnInput_Implementation(FKey Key, EInputEvent KeyEvent) override;
257
258protected:
259
260
261
262};
263
EGripMovementReplicationSettings
UENUM(Blueprintable)
ESecondaryGripType
UENUM(Blueprintable)
EGripCollisionType
UENUM(Blueprintable)
EGripLateUpdateSettings
UENUM(Blueprintable)
EGripInterfaceTeleportBehavior
UENUM(Blueprintable)
EVRInteractibleMountAxis
UENUM(Blueprintable)
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController)
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = (VRExpansionPlugin))
FVector InitialInteractorDropLocation
bool bReplicateMovement
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface|Replication")
float SecondarySlotRange
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripSettings")
FTransform InitialRelativeTransform
float PrimarySlotRange
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripSettings")
float Damping
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
float FlipingZone
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRMountComponent")
FVector InitialInteractorLocation
FBPGripPair HoldingGrip
UPROPERTY(BlueprintReadOnly, Category = "VRGripInterface")
FGameplayTagContainer GameplayTags
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "GameplayTags")
float BreakDistance
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
EGripMovementReplicationSettings MovementReplicationSetting
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
float Stiffness
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
float FlipReajustYawSpeed
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRMountComponent")
bool bDenyGripping
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface", meta = (ScriptName = "IsDen...
bool bIsHeld
UPROPERTY(BlueprintReadOnly, Category = "VRGripInterface", meta = (ScriptName = "IsCurrentlyHeld"))
bool bRepGameplayTags
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
EVRInteractibleMountAxis MountRotationAxis
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRMountComponent")
int GripPriority
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripSettings")
virtual void GetOwnedGameplayTags(FGameplayTagContainer &TagContainer) const override
void ResetInitialMountLocation()
UFUNCTION(BlueprintCallable, Category = "VRMountComponent")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary|TransformNetQuantize", meta = (HasNativeMake = ...