5#include "NavigationSystem.h"
35 FRepMovement& MovementRep = GetReplicatedMovement_Mutable();
38 MovementRep.LocationQuantizationLevel = EVectorQuantization::RoundTwoDecimals;
42 cap->SetCapsuleSize(16.0f, 96.0f);
43 cap->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
44 cap->SetCollisionResponseToChannel(ECollisionChannel::ECC_WorldStatic, ECollisionResponse::ECR_Block);
68 if (GetMovementComponent())
121 MinNetUpdateFrequency = 100.0f;
126 MovementRep.RotationQuantizationLevel = ERotatorQuantization::ShortComponents;
141 Super::PossessedBy(NewController);
147 Super::OnRep_Controller();
154 Super::OnRep_PlayerState();
159 QUICK_SCOPE_CYCLE_COUNTER(STAT_Character_PostInitComponents);
161 Super::PostInitializeComponents();
163 if (!IsPendingKill())
173 if (myMesh->PrimaryComponentTick.bCanEverTick && GetMovementComponent())
175 myMesh->PrimaryComponentTick.AddPrerequisite(GetMovementComponent(), GetMovementComponent()->PrimaryComponentTick);
179 if (GetCharacterMovement() && GetCapsuleComponent())
181 GetCharacterMovement()->UpdateNavAgent(*GetCapsuleComponent());
184 if (
Controller ==
nullptr && GetNetMode() != NM_Client)
186 if (GetCharacterMovement() && GetCharacterMovement()->bRunPhysicsWithNoController)
188 GetCharacterMovement()->SetDefaultMovementMode();
216void AVRBaseCharacter::GetLifetimeReplicatedProps(TArray< class FLifetimeProperty > & OutLifetimeProps)
const
218 Super::GetLifetimeReplicatedProps(OutLifetimeProps);
223 DISABLE_REPLICATED_PRIVATE_PROPERTY(
AActor, ReplicatedMovement);
230 Super::PreReplication(ChangedPropertyTracker);
249 SetSeatedMode(SeatParent, bSetSeatedMode, TargetTransform, InitialRelCameraTransform, AllowedRadius, AllowedRadiusThreshold, bZeroToHead, PostSeatedMovementMode);
295void AVRBaseCharacter::Server_SendTransformCamera_Implementation(
FBPVRComponentPosRep NewTransform)
307void AVRBaseCharacter::Server_SendTransformLeftController_Implementation(
FBPVRComponentPosRep NewTransform)
313bool AVRBaseCharacter::Server_SendTransformLeftController_Validate(
FBPVRComponentPosRep NewTransform)
319void AVRBaseCharacter::Server_SendTransformRightController_Implementation(
FBPVRComponentPosRep NewTransform)
325bool AVRBaseCharacter::Server_SendTransformRightController_Validate(
FBPVRComponentPosRep NewTransform)
332 return OriginalLocation;
338 if (bRegisterAsTeleport)
340 if (GetNetMode() < ENetMode::NM_Client)
349 if (GetNetMode() < ENetMode::NM_Client)
351 if (bRegisterAsTeleport)
370 FRepMovement& ReppedMovement = GetReplicatedMovement_Mutable();
379 Super::OnRep_ReplicatedMovement();
381 if (!IsLocallyControlled())
404 Super::GatherCurrentMovement();
406 FRepMovement ReppedMovement = this->GetReplicatedMovement();
428 if (UPrimitiveComponent * root = Cast<UPrimitiveComponent>(GetRootComponent()))
447 if (this->GetLocalRole() == ROLE_SimulatedProxy)
465 if (this->GetLocalRole() == ROLE_SimulatedProxy)
488 if (UPrimitiveComponent * root = Cast<UPrimitiveComponent>(GetRootComponent()))
495 FAttachmentTransformRules TransformRule = FAttachmentTransformRules::SnapToTargetNotIncludingScale;
496 TransformRule.bWeldSimulatedBodies =
true;
500 if (this->GetLocalRole() == ROLE_SimulatedProxy)
509 root->SetCollisionEnabled(ECollisionEnabled::NoCollision);
516 bUseControllerRotationYaw =
false;
529 if (this->GetLocalRole() == ROLE_AutonomousProxy)
534 if (ClientData->SavedMoves.Num())
543 root->SetCollisionEnabled(ECollisionEnabled::NoCollision);
552 bUseControllerRotationYaw =
false;
560 DetachFromActor(FDetachmentTransformRules::KeepWorldTransform);
562 if (this->GetLocalRole() == ROLE_SimulatedProxy)
564 root->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
597 if (this->GetLocalRole() == ROLE_Authority)
604 ServerData->CurrentClientTimeStamp = 0.0f;
605 ServerData->PendingAdjustment = FClientAdjustment();
609 ServerData->ServerTimeStampLastServerMove = 0.f;
610 ServerData->bForceClientUpdate =
false;
611 ServerData->TimeDiscrepancy = 0.f;
612 ServerData->bResolvingTimeDiscrepancy =
false;
613 ServerData->TimeDiscrepancyResolutionMoveDeltaOverride = 0.f;
614 ServerData->TimeDiscrepancyAccumulatedClientDeltasSinceLastServerTick = 0.f;
633 root->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
653 OrigLocation.Z = 0.0f;
662 bLastOverThreshold =
false;
667 float AbsDistance = FMath::Abs(FVector::Dist(OrigLocation, NewLoc));
675 FVector diff = NewLoc - OrigLocation;
704 if (!this->HasAuthority())
763 FRotator NewRotation;
768 NewRotation = (NewRotation.Quaternion().Inverse() * NewTrans.GetRotation()).Rotator();
769 NewLocation = NewTrans.GetTranslation();
770 NewLocation -= NewRotation.RotateVector(PivotPoint + (-DeltaLoc));
773 SetActorRelativeTransform(FTransform(NewRotation, NewLocation, GetCapsuleComponent()->GetRelativeScale3D()));
779 AController* OwningController = GetController();
782 FRotator NewRotation;
783 FVector OrigLocation = GetActorLocation();
787 NewRotation = bUseControllerRotationYaw && OwningController ? OwningController->GetControlRotation() : GetActorRotation();
791 NewRotation.Pitch = 0.0f;
792 NewRotation.Roll = 0.0f;
795 NewLocation = OrigLocation + NewRotation.RotateVector(PivotPoint);
796 NewRotation = (NewRotation.Quaternion() * DeltaRot.Quaternion()).Rotator();
797 NewLocation -= NewRotation.RotateVector(PivotPoint);
799 if (bUseControllerRotationYaw && OwningController )
800 OwningController->SetControlRotation(NewRotation);
803 SetActorLocationAndRotation(NewLocation, NewRotation);
804 return NewLocation - OrigLocation;
809 AController* OwningController = GetController();
812 FRotator NewRotation;
813 FVector OrigLocation = GetActorLocation();
817 FRotator OrigRotation = bUseControllerRotationYaw && OwningController ? OwningController->GetControlRotation() : GetActorRotation();
825 if (bAccountForHMDRotation)
828 NewRotation = (NewRot.Quaternion() * NewRotation.Quaternion().Inverse()).Rotator();
831 NewRotation = NewRot;
833 NewLocation = OrigLocation + OrigRotation.RotateVector(PivotPoint);
835 NewLocation -= NewRotation.RotateVector(PivotPoint);
837 if (bUseControllerRotationYaw && OwningController )
838 OwningController->SetControlRotation(NewRotation);
841 SetActorLocationAndRotation(NewLocation, NewRotation);
842 return NewLocation - OrigLocation;
847 AController* OwningController = GetController();
850 FRotator NewRotation;
860 if (bAccountForHMDRotation)
863 NewRotation = (NewRot.Quaternion() * NewRotation.Quaternion().Inverse()).Rotator();
866 NewRotation = NewRot;
868 NewLocation = NewLoc;
870 NewLocation -= NewRotation.RotateVector(PivotPoint);
872 if (bUseControllerRotationYaw && OwningController )
873 OwningController->SetControlRotation(NewRotation);
876 SetActorLocationAndRotation(NewLocation, NewRotation,
false,
nullptr, bTeleport ? ETeleportType::TeleportPhysics : ETeleportType::None);
877 return NewLocation - NewLoc;
883 FRotator NewRotation;
885 PivotOffsetVal.Z = 0.0f;
888 NewLocation = NewLoc - PivotOffsetVal;
893 SetActorLocation(NewLocation,
false,
nullptr, bTeleport ? ETeleportType::TeleportPhysics : ETeleportType::None);
894 return NewLocation - NewLoc;
902 if (!FMath::IsNearlyEqual(NewRadius, Capsule->GetUnscaledCapsuleRadius()) || !FMath::IsNearlyEqual(NewHalfHeight, Capsule->GetUnscaledCapsuleHalfHeight()))
903 Capsule->SetCapsuleSize(NewRadius, NewHalfHeight, bUpdateOverlaps);
914 if (!FMath::IsNearlyEqual(HalfHeight, Capsule->GetUnscaledCapsuleHalfHeight()))
915 Capsule->SetCapsuleHalfHeight(HalfHeight, bUpdateOverlaps);
922void AVRBaseCharacter::ExtendedSimpleMoveToLocation(
const FVector& GoalLocation,
float AcceptanceRadius,
bool bStopOnOverlap,
bool bUsePathfinding,
bool bProjectDestinationToNavigation,
bool bCanStrafe, TSubclassOf<UNavigationQueryFilter> FilterClass,
bool bAllowPartialPaths)
924 UNavigationSystemV1* NavSys =
Controller ? FNavigationSystem::GetCurrent<UNavigationSystemV1>(
Controller->GetWorld()) :
nullptr;
925 if (NavSys ==
nullptr ||
Controller ==
nullptr )
927 UE_LOG(LogBaseVRCharacter,
Warning, TEXT(
"UVRSimpleCharacter::ExtendedSimpleMoveToLocation called for NavSys:%s Controller:%s (if any of these is None then there's your problem"),
928 *GetNameSafe(NavSys), *GetNameSafe(
Controller));
938 if (PFollowComp ==
nullptr)
940 PFollowComp = NewObject<UVRPathFollowingComponent>(
Controller);
941 PFollowComp->RegisterComponentWithWorld(
Controller->GetWorld());
942 PFollowComp->Initialize();
946 if (PFollowComp ==
nullptr)
948 UE_LOG(LogBaseVRCharacter,
Warning, TEXT(
"ExtendedSimpleMoveToLocation - No PathFollowingComponent Found"));
952 if (!PFollowComp->IsPathFollowingAllowed())
954 UE_LOG(LogBaseVRCharacter,
Warning, TEXT(
"ExtendedSimpleMoveToLocation - Path Following Movement Is Not Set To Allowed"));
958 EPathFollowingReachMode ReachMode;
960 ReachMode = EPathFollowingReachMode::OverlapAgent;
962 ReachMode = EPathFollowingReachMode::ExactLocation;
964 bool bAlreadyAtGoal =
false;
967 bAlreadyAtGoal = pathcomp->HasReached(GoalLocation, ReachMode);
969 bAlreadyAtGoal = PFollowComp->HasReached(GoalLocation, ReachMode);
972 if (PFollowComp->GetStatus() != EPathFollowingStatus::Idle)
974 if (GetNetMode() == ENetMode::NM_Client)
977 PFollowComp->AbortMove(*NavSys, FPathFollowingResultFlags::ForcedScript | FPathFollowingResultFlags::NewRequest
978 , FAIRequestID::AnyRequest, EPathFollowingVelocityMode::Reset );
982 PFollowComp->AbortMove(*NavSys, FPathFollowingResultFlags::ForcedScript | FPathFollowingResultFlags::NewRequest
983 , FAIRequestID::AnyRequest, bAlreadyAtGoal ? EPathFollowingVelocityMode::Reset : EPathFollowingVelocityMode::Keep);
989 PFollowComp->RequestMoveWithImmediateFinish(EPathFollowingResult::Success);
993 const ANavigationData* NavData = NavSys->GetNavDataForProps(
Controller->GetNavAgentPropertiesRef());
997 FPathFindingResult Result = NavSys->FindPathSync(Query);
998 if (Result.IsSuccessful())
1000 FAIMoveRequest MoveReq(GoalLocation);
1001 MoveReq.SetUsePathfinding(bUsePathfinding);
1002 MoveReq.SetAllowPartialPath(bAllowPartialPaths);
1003 MoveReq.SetProjectGoalLocation(bProjectDestinationToNavigation);
1005 MoveReq.SetAcceptanceRadius(AcceptanceRadius);
1006 MoveReq.SetReachTestIncludesAgentRadius(bStopOnOverlap);
1007 MoveReq.SetCanStrafe(bCanStrafe);
1008 MoveReq.SetReachTestIncludesGoalRadius(
true);
1010 PFollowComp->RequestMove(MoveReq, Result.Path);
1012 else if (PFollowComp->GetStatus() != EPathFollowingStatus::Idle)
1014 PFollowComp->RequestMoveWithImmediateFinish(EPathFollowingResult::Invalid);
1029 FNavPathSharedPtr NavPtr = PFollowComp->GetPath();
1030 if (NavPtr.IsValid())
1032 TArray<FNavPathPoint>& NavPoints = NavPtr->GetPathPoints();
1033 if (NavPoints.Num())
1035 FTransform BaseTransform = FTransform::Identity;
1036 if (
AActor* BaseActor = NavPtr->GetBaseActor())
1038 BaseTransform = BaseActor->GetActorTransform();
1041 NavigationPointList.Empty(NavPoints.Num());
1042 NavigationPointList.AddUninitialized(NavPoints.Num());
1045 for (FNavPathPoint& pt : NavPoints)
1047 NavigationPointList[counter++] = BaseTransform.TransformPosition(pt.Location);
EVRMoveAction
UENUM(Blueprintable)
EVRConjoinedMovementModes
UENUM(BlueprintType)
DEFINE_LOG_CATEGORY(LogBaseVRCharacter)
FVRSeatedCharacterInfo SeatInformation
UPROPERTY(BlueprintReadOnly, Replicated, EditAnywhere, Category = "Seating", ReplicatedUsing = OnRep_...
void InitSeatedModeTransition()
USceneComponent * VRProxyComponent
UPROPERTY(Category = VRBaseCharacter, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess ...
bool SetSeatedMode(USceneComponent *SeatParent, bool bSetSeatedMode, FTransform TargetTransform, FTransform InitialRelCameraTransform, float AllowedRadius=40.0f, float AllowedRadiusThreshold=20.0f, bool bZeroToHead=true, EVRConjoinedMovementModes PostSeatedMovementMode=EVRConjoinedMovementModes::C_MOVE_Walking)
FVRReplicatedCapsuleHeight ReplicatedCapsuleHeight
UPROPERTY(Replicated, ReplicatedUsing = OnRep_CapsuleHeight)
FVRSeatThresholdChangedSignature OnSeatThreshholdChanged_Bind
UPROPERTY(BlueprintAssignable, Category = "Seating")
static FName ReplicatedCameraComponentName
virtual void SetCharacterSizeVR(float NewRadius, float NewHalfHeight, bool bUpdateOverlaps=true)
UFUNCTION(BlueprintCallable, Category = "BaseVRCharacter")
void OnSeatedModeChanged(bool bNewSeatedMode, bool bWasAlreadySeated)
UFUNCTION(BlueprintNativeEvent, Category = "Seating")
virtual void OnRep_SeatedCharInfo()
UFUNCTION()
virtual void GatherCurrentMovement() override
virtual void OnEndWallPushback_Implementation()
USceneComponent * NetSmoother
UPROPERTY(Category = VRBaseCharacter, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess ...
FVector SetActorRotationVR(FRotator NewRot, bool bUseYawOnly=true, bool bAccountForHMDRotation=true)
UFUNCTION(BlueprintCallable, Category = "BaseVRCharacter|VRLocations")
UGripMotionControllerComponent * RightMotionController
UPROPERTY(Category = VRBaseCharacter, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess ...
FVector SetActorLocationVR(FVector NewLoc, bool bTeleport)
UFUNCTION(BlueprintCallable, Category = "BaseVRCharacter|VRLocations")
virtual void PreReplication(IRepChangedPropertyTracker &ChangedPropertyTracker) override
virtual FVector GetTeleportLocation(FVector OriginalLocation)
UFUNCTION(BlueprintPure, Category = "VRGrip")
static FName LeftMotionControllerComponentName
void ZeroToSeatInformation()
bool bFlagTeleportedGrips
struct FRepMovementVRCharacter ReplicatedMovementVR
UPROPERTY(ReplicatedUsing = OnRep_ReplicatedMovement)
void Server_SendTransformRightController(FBPVRComponentPosRep NewTransform)
UFUNCTION(Unreliable, Server, WithValidation)
virtual void OnBeginWallPushback_Implementation(FHitResult HitResultOfImpact, bool bHadLocomotionInput, FVector HmdInput)
FVector AddActorWorldRotationVR(FRotator DeltaRot, bool bUseYawOnly=true)
UFUNCTION(BlueprintCallable, Category = "BaseVRCharacter|VRLocations")
FVector PausedTrackingLoc
virtual void OnRep_PlayerState() override
FVector SetActorLocationAndRotationVR(FVector NewLoc, FRotator NewRot, bool bUseYawOnly=true, bool bAccountForHMDRotation=true, bool bTeleport=false)
UFUNCTION(BlueprintCallable, Category = "BaseVRCharacter|VRLocations")
AVRBaseCharacter(const FObjectInitializer &ObjectInitializer=FObjectInitializer::Get())
virtual void OnClimbingSteppedUp_Implementation()
static FName VRProxyComponentName
virtual void ExtendedSimpleMoveToLocation(const FVector &GoalLocation, float AcceptanceRadius=-1, bool bStopOnOverlap=false, bool bUsePathfinding=true, bool bProjectDestinationToNavigation=true, bool bCanStrafe=false, TSubclassOf< UNavigationQueryFilter > FilterClass=NULL, bool bAllowPartialPath=true)
UFUNCTION(BlueprintCallable, Category = "VRBaseCharacter|Navigation", Meta = (AdvancedDisplay = "bSto...
static FName SmoothingSceneParentComponentName
FTransform OffsetComponentToWorld
UPROPERTY(BlueprintReadOnly, Transient, Category = "VRExpansionLibrary")
static FName RightMotionControllerComponentName
void TickSeatInformation(float DeltaTime)
FVRPlayerStateReplicatedSignature OnPlayerStateReplicated_Bind
UPROPERTY(BlueprintAssignable, Category = "VRMovement")
bool VRReplicateCapsuleHeight
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRBaseCharacter")
virtual void OnRep_Controller() override
static FName ParentRelativeAttachmentComponentName
virtual void PostInitializeComponents() override
bool GetCurrentNavigationPathPoints(TArray< FVector > &NavigationPointList)
UFUNCTION(BlueprintCallable, Category = "VRBaseCharacter|Navigation")
void SetSeatRelativeLocationAndRotationVR(FVector LocDelta)
virtual void OnCustomMoveActionPerformed_Implementation(EVRMoveAction MoveActionType, FVector MoveActionVector, FRotator MoveActionRotator, uint8 MoveActionFlags)
virtual void PossessedBy(AController *NewController)
UVRBaseCharacterMovementComponent * VRMovementReference
UPROPERTY(Category = VRBaseCharacter, VisibleAnywhere, Transient, BlueprintReadOnly,...
UReplicatedVRCameraComponent * VRReplicatedCamera
UPROPERTY(Category = VRBaseCharacter, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess ...
virtual void NotifyOfTeleport(bool bRegisterAsTeleport=true)
UFUNCTION(BlueprintCallable, Category = "VRGrip")
TSubclassOf< UNavigationQueryFilter > DefaultNavigationFilterClass
UPROPERTY(BlueprintReadWrite, Category = AI)
UGripMotionControllerComponent * LeftMotionController
UPROPERTY(Category = VRBaseCharacter, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess ...
void OnSeatThreshholdChanged(bool bIsWithinThreshold, float ToThresholdScaler)
UFUNCTION(BlueprintNativeEvent, Category = "Seating")
bool bUseExperimentalUnseatModeFix
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRBaseCharacter")
virtual void SetCharacterHalfHeightVR(float HalfHeight, bool bUpdateOverlaps=true)
UFUNCTION(BlueprintCallable, Category = "BaseVRCharacter")
UParentRelativeAttachmentComponent * ParentRelativeAttachment
UPROPERTY(Category = VRBaseCharacter, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess ...
void Server_SendTransformLeftController(FBPVRComponentPosRep NewTransform)
UFUNCTION(Unreliable, Server, WithValidation)
virtual void OnRep_ReplicatedMovement() override
AVRPlayerController * OwningVRPlayerController
UPROPERTY(Transient, DuplicateTransient)
FVector GetVRLocation_Inline() const
void Server_SendTransformCamera(FBPVRComponentPosRep NewTransform)
UFUNCTION(Unreliable, Server, WithValidation)
void PostTeleportMoveGrippedObjects()
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
bool bOffsetByHMD
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Advanced|Tracking")
VRBaseCharTransformRPC_Pointer OverrideSendTransform
bool bOffsetByHMD
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRExpansionLibrary")
bool bOffsetByHMD
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera")
VRBaseCharTransformRPC_Pointer OverrideSendTransform
FORCEINLINE void ApplyReplicatedMovementMode(EVRConjoinedMovementModes &NewMovementMode, bool bClearMovementMode=false)
static FRotator GetHMDPureYaw_I(FRotator HMDRotation)
bool bJustTeleported
UPROPERTY(Transient)
bool bJustTeleportedGrips
UPROPERTY(Transient)
AActor * Owner
UPROPERTY(Transient)
FVector_NetQuantize100 PausedTrackingLoc
UPROPERTY(Transient)
bool bPausedTracking
UPROPERTY(Transient)
float PausedTrackingRot
UPROPERTY(Transient)
FRepMovementVRCharacter()
float CapsuleHeight
UPROPERTY()
FTransform_NetQuantize StoredTargetTransform
UPROPERTY(BlueprintReadOnly, Category = "CharacterSeatInfo")
float AllowedRadius
UPROPERTY(EditAnywhere, BlueprintReadWrite, NotReplicated, Category = "CharacterSeatInfo",...
bool bIsOverThreshold
UPROPERTY(BlueprintReadOnly, NotReplicated, Category = "CharacterSeatInfo")
bool bOriginalControlRotation
EVRConjoinedMovementModes PostSeatedMovementMode
UPROPERTY(BlueprintReadOnly, Category = "CharacterSeatInfo")
FTransform_NetQuantize InitialRelCameraTransform
UPROPERTY(BlueprintReadOnly, Category = "CharacterSeatInfo")
float CurrentThresholdScaler
UPROPERTY(BlueprintReadOnly, NotReplicated, Category = "CharacterSeatInfo")
USceneComponent * SeatParent
UPROPERTY(BlueprintReadOnly, Category = "CharacterSeatInfo")
bool bZeroToHead
UPROPERTY(BlueprintReadOnly, Category = "CharacterSeatInfo")
bool bSitting
UPROPERTY(BlueprintReadOnly, Category = "CharacterSeatInfo")
float AllowedRadiusThreshold
UPROPERTY(EditAnywhere, BlueprintReadWrite, NotReplicated, Category = "CharacterSeatInfo",...