A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
VRCharacterMovementComponent.h
Go to the documentation of this file.
1// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4#include "CoreMinimal.h"
5#include "AI/Navigation/NavigationAvoidanceTypes.h"
6#include "AI/RVOAvoidanceInterface.h"
7#include "AITypes.h"
8#include "VRRootComponent.h"
9#include "Navigation/PathFollowingComponent.h"
10#include "AI/Navigation/NavigationTypes.h"
11//#include "AI/Navigation/NavigationSystem.h"
12#include "Animation/AnimationAsset.h"
13#include "Engine/EngineBaseTypes.h"
14#include "Engine/EngineTypes.h"
15#include "GameFramework/PawnMovementComponent.h"
16#include "Interfaces/NetworkPredictionInterface.h"
17#include "WorldCollision.h"
18#include "Runtime/Launch/Resources/Version.h"
20#include "GameFramework/CharacterMovementReplication.h"
21#include "VRCharacterMovementComponent.generated.h"
22
23class FDebugDisplayInfo;
24class ACharacter;
25class AVRCharacter;
26
27DECLARE_LOG_CATEGORY_EXTERN(LogVRCharacterMovement, Log, All);
28
30//typedef TSharedPtr<class FSavedMove_Character> FSavedMovePtr;
31
32
33
34//FCharacterMoveResponseDataContainer VRMoveResponseDataContainer;
35
36
37//=============================================================================
51//DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FAIMoveCompletedSignature, FAIRequestID, RequestID, EPathFollowingResult::Type, Result);
52
53UCLASS()
55{
57public:
59 UPROPERTY(BlueprintReadOnly, Transient, Category = VRMovement)
60 UVRRootComponent * VRRootCapsule;
61
63 static const float CLIMB_SWEEP_EDGE_REJECT_DISTANCE;
64 virtual bool IsWithinClimbingEdgeTolerance(const FVector& CapsuleLocation, const FVector& TestImpactPoint, const float CapsuleRadius) const;
65 virtual bool VRClimbStepUp(const FVector& GravDir, const FVector& Delta, const FHitResult &InHit, FStepDownResult* OutStepDownResult = nullptr) override;
67 virtual bool IsWithinEdgeTolerance(const FVector& CapsuleLocation, const FVector& TestImpactPoint, const float CapsuleRadius) const override;
68
69 // Allow merging movement replication (may cause issues when >10 players due to capsule location
70 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VRCharacterMovementComponent")
71 bool bAllowMovementMerging;
72
73 // If true we will run client corrections off of the HMD location instead of actor, this is a settable value to allow backwards compatibility
74 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VRCharacterMovementComponent")
75 bool bRunClientCorrectionToHMD;
76
77 // Higher values will cause more slide but better step up
78 //UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRCharacterMovementComponent", meta = (ClampMin = "0.01", UIMin = "0", ClampMax = "1.0", UIMax = "1"))
79 //float WallRepulsionMultiplier;
80
86 virtual void Crouch(bool bClientSimulation = false) override;
87
92 virtual void UnCrouch(bool bClientSimulation = false) override;
93
95 //virtual bool CanCrouchInCurrentState() const;
96
98 // Navigation Functions
100
102 //UPROPERTY(BlueprintAssignable, meta = (DisplayName = "MoveCompleted"))
103 //FAIMoveCompletedSignature ReceiveMoveCompleted;
104
105 virtual FBasedPosition GetActorFeetLocationBased() const override;
106
113 virtual bool TryToLeaveNavWalking() override;
114
115
116 virtual void PhysNavWalking(float deltaTime, int32 Iterations) override;
117 virtual void ProcessLanded(const FHitResult& Hit, float remainingTime, int32 Iterations) override;
118
119 void PostPhysicsTickComponent(float DeltaTime, FCharacterMovementComponentPostPhysicsTickFunction& ThisTickFunction) override;
120 void SimulateMovement(float DeltaSeconds) override;
121 void MoveSmooth(const FVector& InVelocity, const float DeltaSeconds, FStepDownResult* OutStepDownResult) override;
122 //void PerformMovement(float DeltaSeconds) override;
123
125 // End Navigation Functions
127
128
130 // Client adjustment overrides to allow for rotation
132
133 virtual void ClientHandleMoveResponse(const FCharacterMoveResponseDataContainer& MoveResponse) override;
134
135 //virtual void SendClientAdjustment() override;
142 virtual void ServerMoveHandleClientErrorVR(float ClientTimeStamp, float DeltaTime, const FVector& Accel, const FVector& RelativeClientLocation, float ClientYaw, UPrimitiveComponent* ClientMovementBase, FName ClientBaseBoneName, uint8 ClientMovementMode);
143
148 virtual bool ServerCheckClientErrorVR(float ClientTimeStamp, float DeltaTime, const FVector& Accel, const FVector& ClientWorldLocation, float ClientYaw, const FVector& RelativeClientLocation, UPrimitiveComponent* ClientMovementBase, FName ClientBaseBoneName, uint8 ClientMovementMode);
149
151 virtual void ClientAdjustPositionVR_Implementation(float TimeStamp, FVector NewLoc, uint16 NewYaw, FVector NewVel, UPrimitiveComponent* NewBase, FName NewBaseBoneName, bool bHasBase, bool bBaseRelativePosition, uint8 ServerMovementMode);
152
153
155 // Replication Functions
157
159 // Network RPCs for movement
161
171 // Using my own as I don't want to cast the standard fsavedmove
172 //virtual void CallServerMove(const class FSavedMove_Character* NewMove, const class FSavedMove_Character* OldMove) override;
173
174 virtual void ServerMove_PerformMovement(const FCharacterNetworkMoveData& MoveData) override;
175
176 FNetworkPredictionData_Client* GetPredictionData_Client() const override;
177 FNetworkPredictionData_Server* GetPredictionData_Server() const override;
178
180 // End Replication Functions
182
186 UVRCharacterMovementComponent(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
187 virtual void OnRegister() override;
188
189 float ImmersionDepth() const override;
190 bool CanCrouch();
191
192 // Don't really need to override this at all, it doesn't work that well even when fixed in VR
193 //void VisualizeMovement() const override;
194
195
196 /*
197 bool HasRootMotion() const
198 {
199 return RootMotionParams.bHasRootMotion;
200 }*/
201
202 // Had to modify this, since every frame can start in penetration (capsule component moves into wall before movement tick)
203 // It was throwing out the initial hit and not calling "step up", now I am only checking for penetration after adjustment but keeping the initial hit for step up.
204 // this makes for FAR more responsive step ups.
205 // I WILL need to override these for flying / swimming as well
206 bool SafeMoveUpdatedComponent(const FVector& Delta, const FQuat& NewRotation, bool bSweep, FHitResult& OutHit, ETeleportType Teleport = ETeleportType::None);
207 bool SafeMoveUpdatedComponent(const FVector& Delta, const FRotator& NewRotation, bool bSweep, FHitResult& OutHit, ETeleportType Teleport = ETeleportType::None);
208
209 // This is here to force it to call the correct SafeMoveUpdatedComponent functions for floor movement
210 virtual void MoveAlongFloor(const FVector& InVelocity, float DeltaSeconds, FStepDownResult* OutStepDownResult) override;
211
212 // Modify for correct location
213 virtual void ApplyRepulsionForce(float DeltaSeconds) override;
214
215 // Update BaseOffset to be zero
216 virtual void UpdateBasedMovement(float DeltaSeconds) override;
217
218 // Stop subtracting the capsules half height
219 virtual FVector GetImpartedMovementBaseVelocity() const override;
220
221 // Cheating at the relative collision detection
222 void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction);
223
224 // Need to fill our capsule component variable here and override the default tick ordering
225 virtual void SetUpdatedComponent(USceneComponent* NewUpdatedComponent) override;
226
227 // Correct an offset sweep test
228 virtual void ReplicateMoveToServer(float DeltaTime, const FVector& NewAcceleration) override;
229
230 // Always called with the capsulecomponent location, no idea why it doesn't just get it inside it already
231 // Had to force it within the function to use VRLocation instead.
232 virtual void FindFloor(const FVector& CapsuleLocation, FFindFloorResult& OutFloorResult, bool bCanUseCachedLocation, const FHitResult* DownwardSweepResult = NULL) const;
233
234 // Need to use actual capsule location for step up
235 bool StepUp(const FVector& GravDir, const FVector& Delta, const FHitResult &InHit, FStepDownResult* OutStepDownResult = NULL) override;
236
237 virtual FVector GetPenetrationAdjustment(const FHitResult& Hit) const override;
238
239 // MOVED THIS TO THE BASE VR CHARACTER MOVEMENT COMPONENT
240 // Also added a control variable for it there
241 // Skip physics channels when looking for floor
242 /*virtual bool FloorSweepTest(
243 FHitResult& OutHit,
244 const FVector& Start,
245 const FVector& End,
246 ECollisionChannel TraceChannel,
247 const struct FCollisionShape& CollisionShape,
248 const struct FCollisionQueryParams& Params,
249 const struct FCollisionResponseParams& ResponseParam
250 ) const override;*/
251
252 // Multiple changes to support relative motion and ledge sweeps
253 virtual void PhysWalking(float deltaTime, int32 Iterations) override;
254
255 // Supporting the direct move injection
256 virtual void PhysFlying(float deltaTime, int32 Iterations) override;
257
258 // Need to use VR location, was defaulting to actor
259 virtual bool ShouldCheckForValidLandingSpot(float DeltaTime, const FVector& Delta, const FHitResult& Hit) const override;
260
261 // Overriding the physfalling because valid landing spots were computed incorrectly.
262 virtual void PhysFalling(float deltaTime, int32 Iterations) override;
263
264 virtual void PhysSwimming(float deltaTime, int32 Iterations) override;
273 void StartSwimmingVR(FVector OldLocation, FVector OldVelocity, float timeTick, float remainingTime, int32 Iterations);
274
275 /* Swimming uses gravity - but scaled by (1.f - buoyancy) */
276 float SwimVR(FVector Delta, FHitResult& Hit);
277
279 virtual bool CheckWaterJump(FVector CheckPoint, FVector& WallNormal) override;
280
281 // Shouldn't need to override this
283 //FVector FindWaterLine(FVector Start, FVector End) override;
284
285 // Just calls find floor
287 //virtual bool IsValidLandingSpot(const FVector& CapsuleLocation, const FHitResult& Hit) const override;
288
289 // Making sure that impulses are correct
290 virtual void CapsuleTouched(UPrimitiveComponent* OverlappedComp, AActor* Other, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) override;
291 virtual void StoreSetTrackingPaused(bool bNewTrackingPaused) override;
292};
293
294
295class VREXPANSIONPLUGIN_API FSavedMove_VRCharacter : public FSavedMove_VRBaseCharacter
296{
297
298public:
299
300 virtual void SetInitialPosition(ACharacter* C);
301 virtual void PrepMoveFor(ACharacter* Character) override;
302
304 {}
305
306};
307
308// Need this for capsule location replication
310{
311public:
314 {
315
316 }
318 FSavedMovePtr AllocateNewMove()
319 {
320 return FSavedMovePtr(new FSavedMove_VRCharacter());
321 }
322};
324
325// Need this for capsule location replication?????
331 {
333 }
334
335 FSavedMovePtr AllocateNewMove()
336 {
337 return FSavedMovePtr(new FSavedMove_VRCharacter());
338 }
339};
DECLARE_LOG_CATEGORY_EXTERN(LogVRCharacterMovement, Log, All)
UCLASS()
Definition VRCharacter.h:23
FNetworkPredictionData_Client_VRCharacter(const UCharacterMovementComponent &ClientMovement)
FNetworkPredictionData_Server_VRCharacter(const UCharacterMovementComponent &ClientMovement)
virtual bool VRClimbStepUp(const FVector &GravDir, const FVector &Delta, const FHitResult &InHit, FStepDownResult *OutStepDownResult=nullptr)
virtual void StoreSetTrackingPaused(bool bNewTrackingPaused)
virtual void SetUpdatedComponent(USceneComponent *NewUpdatedComponent)
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override
bool bAllowMovementMerging
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VRCharacterMovementComponent")
UVRRootComponent * VRRootCapsule
UPROPERTY(BlueprintReadOnly, Transient, Category = VRMovement)
bool bRunClientCorrectionToHMD
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VRCharacterMovementComponent")
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = VRExpansionLibrary)