From e5f46ab642b00effb0a87c9dec97e25153583d67 Mon Sep 17 00:00:00 2001
From: Daniel Rupp <daniel.rupp@rwth-aachen.de>
Date: Wed, 29 May 2024 16:55:00 +0200
Subject: [PATCH] fix(navigation): fixes pre-travel avatar position

---
 .../BP_TeleportationComponent.uasset          | Bin 15568 -> 15564 bytes
 .../Navigation/TeleportationComponent.cpp     |  54 +++++++++---------
 .../Private/UI/TeleportVisualizer.cpp         |  50 +++++-----------
 .../Pawn/Navigation/TeleportationComponent.h  |   6 ++
 .../Public/UI/TeleportVisualizer.h            |  36 ++----------
 5 files changed, 51 insertions(+), 95 deletions(-)

diff --git a/Content/Components/Movement/Teleportation/BP_TeleportationComponent.uasset b/Content/Components/Movement/Teleportation/BP_TeleportationComponent.uasset
index d924129f28babb468384a1d11df4dd09f7fa173b..84af73944a752da2e002f5f6cb733d64ffbd855b 100644
GIT binary patch
delta 336
zcmcamd8Ts01;&FDFD5ZYO*UcFv8d!>U|?rpV0g*Tz#zuJzyRWR3NbJ+GB7Y~6=Go6
zE5yKXQ;31#{KCs0XRc;;Y>o+F+bR~kYVr)m97SJY28J0n3@G6L|Ns9F>M}66GB7aA
z*{sUs$;RkD*^tRzAS|=EG%+W$Dz%7#Ysat8&XWz9Og4Yv*u$tG!N9=a6c8Vhnv+_P
zUsQrn81Kx`ePh+l&6l|BS(y&%PQG9+H`!3Yf$5n3<VIt;$rA-k_$(P17-m5oAZ9SR
z(O7NrPXP<24G?CepaoN+Ay{;$pas)h6EIU!$b#vm#pDa-YLhF4rZ66y%qMKme^!Wr
zVWTd@Bqj!i$?t^ZH&+YKR-No_qcYjb(rmJkjpgJVOM%TcR^J#W7g+9@oNbc|0MjyM
AXaE2J

delta 337
zcmX?8d7*N`1;(QjFD5a?@k}nXQMX}WU|^`_VPIfqU|@L5&%huC<@X9PFfcMOFzgg!
zU^pnmz;IWHfgyS0+L;r(oqam*Pv_v(F4#4B24jw5pfCf&9I!DUqagVI|NsAw>M}66
zGB7YK*sRLr$;Rk8*^tRxDl8}@H7B(ozo;ZEv$!-dC$lQGh(WgC)@A3(hD;`#KXL3~
zRFYy~U~meE$EGyinZZb0j&t)lE_+tSqm%gr;+anAPrfK1H@R29gwK$HfngTJ0Sr<G
zlQ#;fP5vri!L$X!3>CCsN;L$FZWXj(T4(}hiV9gUzMbqRw43qhWG-QQ){8<63|lw*
u2_I2q<eFS)sm#baIlxk4vcIM5<dv2@leb%M*u2z|jcM{<3(LvrHmLvu-ef-j

diff --git a/Source/RWTHVRToolkit/Private/Pawn/Navigation/TeleportationComponent.cpp b/Source/RWTHVRToolkit/Private/Pawn/Navigation/TeleportationComponent.cpp
index c2ea22ca..5a0b7668 100644
--- a/Source/RWTHVRToolkit/Private/Pawn/Navigation/TeleportationComponent.cpp
+++ b/Source/RWTHVRToolkit/Private/Pawn/Navigation/TeleportationComponent.cpp
@@ -28,23 +28,6 @@ void UTeleportationComponent::SetupPlayerInput(UInputComponent* PlayerInputCompo
 		GetWorld(), TeleportTraceSystem, VRPawn->GetActorLocation(), FRotator(0), FVector(1), true, true,
 		ENCPoolMethod::AutoRelease, true);
 
-	if (!BPTeleportVisualizer)
-	{
-		UE_LOG(Toolkit, Error,
-			   TEXT("SetupPlayerInput: BPTeleportVisualizer must be set to an Actor class that can be spawned!"));
-		return;
-	}
-
-	TeleportVisualizer =
-		GetWorld()->SpawnActor<ATeleportVisualizer>(BPTeleportVisualizer, VRPawn->GetActorLocation(), VRPawn->GetActorRotation());
-	
-	TeleportTraceComponent->SetVisibility(false);
-	TeleportVisualizer->SetActorHiddenInGame(true);
-	TeleportVisualizer->Platform->SetHiddenInGame(false);
-	FVector PawnBottomLocation = VRPawn->GetActorLocation();
-	PawnBottomLocation.Z = VRPawn->GetActorLocation().Z;
-	TeleportVisualizer->Platform->SetWorldLocation(PawnBottomLocation);
-
 	// simple way of changing the handedness
 	if (bMoveWithRightHand)
 	{
@@ -82,6 +65,29 @@ void UTeleportationComponent::PlayHapticEffect(UHapticFeedbackEffect_Base* Hapti
 	PlayerController->PlayHapticEffect(HapticEffect, EControllerHand::Right,Intensity);
 }
 
+void UTeleportationComponent::BeginPlay()
+{
+	Super::BeginPlay();
+
+	if (!BPTeleportVisualizer)
+	{
+		UE_LOG(Toolkit, Error,
+			   TEXT("SetupPlayerInput: BPTeleportVisualizer must be set to an Actor class that can be spawned!"));
+		return;
+	}
+
+	TeleportVisualizer =
+		GetWorld()->SpawnActor<ATeleportVisualizer>(BPTeleportVisualizer, VRPawn->GetActorLocation(), VRPawn->GetActorRotation());
+	
+	TeleportTraceComponent->SetVisibility(false);
+	TeleportVisualizer->SetActorHiddenInGame(true);
+	TeleportVisualizer->Platform->SetHiddenInGame(false);
+	FVector PawnBottomLocation = VRPawn->GetActorLocation();
+	PawnBottomLocation.Z = VRPawn->GetActorLocation().Z;
+	TeleportVisualizer->Platform->SetWorldLocation(PawnBottomLocation);
+	
+}
+
 void UTeleportationComponent::CleanupTeleportVisualization()
 {
 	if (!VRPawn)
@@ -99,17 +105,11 @@ void UTeleportationComponent::CleanupTeleportVisualization()
 
 void UTeleportationComponent::UpdateUserPreview()
 {
-	FVector NewHMDPos = TeleportVisualizer->GetActorLocation();
-	NewHMDPos.Z += VRPawn->HeadCameraComponent->GetComponentLocation().Z - TeleportVisualizer->Platform->GetComponentLocation().Z; // works since the user stands on the platform (or at least on the same Z level)
+	FVector NewHMDPos = TeleportVisualizer->PreTravelPlatform->GetComponentLocation();
+	NewHMDPos.Z += VRPawn->HeadCameraComponent->GetComponentLocation().Z - TeleportVisualizer->PreTravelPlatform->GetComponentLocation().Z; // works since the user stands on the platform (or at least on the same Z level)
 	
-	TeleportVisualizer->HMDPreview->SetWorldLocationAndRotation(NewHMDPos, VRPawn->HeadCameraComponent->GetComponentRotation());
-	
-	// set rotation of bodypreview
-	TeleportVisualizer->BodyPreview->SetWorldRotation(FRotator(0.0,-90,0));
-
-	FVector NewBodyPreviewPos = TeleportVisualizer->HMDPreview->GetComponentLocation();
-	NewBodyPreviewPos -= FVector(0, 0, TeleportVisualizer->HeadBodyDistance);
-	TeleportVisualizer->BodyPreview->SetWorldLocation(NewBodyPreviewPos);
+	TeleportVisualizer->HMDPreview->SetRelativeLocation(FVector(0,0,NewHMDPos.Z));
+	TeleportVisualizer->HMDPreview->SetWorldRotation(VRPawn->HeadCameraComponent->GetComponentRotation());
 	
 	// Set rotation of vertical indicator arrows to always face pawn
 	FRotator RotationToPawn = UKismetMathLibrary::FindLookAtRotation(TeleportVisualizer->VerticalIndicator->GetComponentLocation(), VRPawn->GetActorLocation());
diff --git a/Source/RWTHVRToolkit/Private/UI/TeleportVisualizer.cpp b/Source/RWTHVRToolkit/Private/UI/TeleportVisualizer.cpp
index 4d4fd2e4..1fe58e68 100644
--- a/Source/RWTHVRToolkit/Private/UI/TeleportVisualizer.cpp
+++ b/Source/RWTHVRToolkit/Private/UI/TeleportVisualizer.cpp
@@ -2,10 +2,7 @@
 
 
 #include "UI/TeleportVisualizer.h"
-
-#include "MovieSceneSequenceID.h"
 #include "NiagaraComponent.h"
-#include "Engine/StaticMeshActor.h"
 
 // Sets default values
 ATeleportVisualizer::ATeleportVisualizer()
@@ -15,8 +12,6 @@ ATeleportVisualizer::ATeleportVisualizer()
 	
 	RootComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Root"));
 	Platform = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PlatformMesh"));
-
-	//Platform->SetStaticMesh(PlatformMesh);
 	
 	// disable collisions of platform meshes
 	FCollisionResponseContainer ResponseContainerPlatform;
@@ -45,62 +40,46 @@ ATeleportVisualizer::ATeleportVisualizer()
 	BodyPreview = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BodyPreviewMesh"));
 	BodyPreview->SetupAttachment(HMDPreview);
 	BodyPreview->SetCollisionEnabled(ECollisionEnabled::NoCollision); // disable collision
-	
-	// ### Ground Plane ###
-	
-	// Create a static mesh component for the HMD preview
-	GroundPlane = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("GroundPlaneMesh"));
+	BodyPreview->SetRelativeRotation(FRotator(0,-90,0));
+	BodyPreview->SetRelativeLocation(FVector(0,0,-HeadBodyDistance));
 
 	FCollisionResponseContainer ResponseContainerGroundPlane;
 	ResponseContainerGroundPlane.SetAllChannels(ECollisionResponse::ECR_Ignore);
-	GroundPlane->SetCollisionResponseToChannels(ResponseContainerGroundPlane); // Ignore collisions on all channels ..
-	GroundPlane->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Block); // .. except pawn channel
 	
-	GroundVisualizationNiagaraComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("GroundParticleSystem"));
-	GroundVisualizationNiagaraComponent->SetupAttachment(RootComponent);  // Attach it to the root component or any other desired parent component
+	//GroundVisualizationNiagaraComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("GroundParticleSystem"));
+	//GroundVisualizationNiagaraComponent->SetupAttachment(PreTravelPlatform);  // Attach it to the root component or any other desired parent component
 	
 	// setup visuals (migrated from CreateTwoStepHandler function)
 
 	HorizontalIndicator = CreateDefaultSubobject<UChildActorComponent>("HorizontalIndicator");
-
+	HorizontalIndicator->SetupAttachment(PreTravelPlatform);
 	
 	VerticalIndicator = CreateDefaultSubobject<UChildActorComponent>("VerticalIndicator");
-
+	VerticalIndicator->SetupAttachment(PreTravelPlatform);
 
 	DefaultHorizontalRange = 4000;
-
-
+	
 }
 
 // Called when the game starts or when spawned
 void ATeleportVisualizer::BeginPlay()
 {
 	Super::BeginPlay();
-
-	FActorSpawnParameters SpawnParameters;
 	
-	HMDPreview->AttachToComponent(PreTravelPlatform,FAttachmentTransformRules(
+	/*HMDPreview->AttachToComponent(PreTravelPlatform,FAttachmentTransformRules(
 												EAttachmentRule::KeepRelative,
 												EAttachmentRule::KeepWorld,
-												EAttachmentRule::KeepRelative, false));
+												EAttachmentRule::KeepRelative, false));*/
 
 
 	BodyPreview->AttachToComponent(HMDPreview, FAttachmentTransformRules(
 											EAttachmentRule::KeepRelative,
 											EAttachmentRule::KeepWorld,
-											EAttachmentRule::KeepRelative, false));
-
-
-	GroundPlane->SetMaterial(0,GroundPlaneMaterial);
-	GroundPlane->AttachToComponent(PreTravelPlatform, FAttachmentTransformRules(
-											EAttachmentRule::SnapToTarget,
-											EAttachmentRule::KeepWorld,
-											EAttachmentRule::KeepRelative,
-											true));
+											EAttachmentRule::KeepRelative,false));
 
-	GroundVisualizationNiagaraComponent->SetAsset(GroundVisualizationNiagaraSystem);
+	//GroundVisualizationNiagaraComponent->SetAsset(GroundVisualizationNiagaraSystem);
 	
-	HorizontalIndicator->AttachToComponent(PreTravelPlatform, FAttachmentTransformRules(
+	/*HorizontalIndicator->AttachToComponent(PreTravelPlatform, FAttachmentTransformRules(
 															EAttachmentRule::SnapToTarget,
 															EAttachmentRule::SnapToTarget,
 															EAttachmentRule::KeepWorld,true));
@@ -108,11 +87,8 @@ void ATeleportVisualizer::BeginPlay()
 	VerticalIndicator->AttachToComponent(PreTravelPlatform, FAttachmentTransformRules(
 															EAttachmentRule::SnapToTarget,
 															EAttachmentRule::SnapToTarget,
-															EAttachmentRule::KeepWorld,true));
+															EAttachmentRule::KeepWorld,true));*/
 	
-	FVector HMDLocation = HMDPreview->GetComponentLocation();
-	HMDLocation.Z -= HeadBodyDistance;
-	BodyPreview->SetWorldLocation(HMDLocation);
 	//GroundVisualizationNiagaraComponent->SetNiagaraVariableFloat("User.BeamWidth", GroundConnectorWidth); // set default width*/
 }
 
diff --git a/Source/RWTHVRToolkit/Public/Pawn/Navigation/TeleportationComponent.h b/Source/RWTHVRToolkit/Public/Pawn/Navigation/TeleportationComponent.h
index 5b8db18f..fffded4a 100644
--- a/Source/RWTHVRToolkit/Public/Pawn/Navigation/TeleportationComponent.h
+++ b/Source/RWTHVRToolkit/Public/Pawn/Navigation/TeleportationComponent.h
@@ -99,6 +99,12 @@ public:
 	ATeleportVisualizer* TeleportVisualizer;
 
 	void PlayHapticEffect(UHapticFeedbackEffect_Base* HapticEffect, float Intensity);
+
+
+
+protected:
+	// Called when the game starts or when spawned
+	virtual void BeginPlay() override;
 	
 private:
 	UPROPERTY()
diff --git a/Source/RWTHVRToolkit/Public/UI/TeleportVisualizer.h b/Source/RWTHVRToolkit/Public/UI/TeleportVisualizer.h
index 85f164cd..7fac1ad3 100644
--- a/Source/RWTHVRToolkit/Public/UI/TeleportVisualizer.h
+++ b/Source/RWTHVRToolkit/Public/UI/TeleportVisualizer.h
@@ -34,28 +34,8 @@ public:
 	UPROPERTY(EditAnywhere)
 	UStaticMeshComponent* PreTravelPlatform;
 	
-	/*UPROPERTY(EditAnywhere)
-	UStaticMesh* PlatformMesh;
-	
-	UPROPERTY(EditAnywhere)
-	UStaticMesh* HMDPreviewMesh;
-	
-	UPROPERTY(EditAnywhere)
-	UStaticMesh* BodyPreviewMesh;
-	
-	UPROPERTY(EditAnywhere)
-	UStaticMesh* GroundPlaneMesh;*/
-
-	/*
-	UPROPERTY(EditAnywhere)
-	TSubclassOf<AActor> HorizontalIndicatorActor;
-	
-	UPROPERTY(EditAnywhere)
-	TSubclassOf<AActor> VerticalIndicatorActor;
-	*/
-	
-	UPROPERTY(EditAnywhere)
-	UNiagaraSystem* GroundVisualizationNiagaraSystem;
+	//UPROPERTY(EditAnywhere)
+	//UNiagaraSystem* GroundVisualizationNiagaraSystem;
 	
 	UPROPERTY(EditAnywhere)
 	UStaticMeshComponent* BodyPreview;
@@ -63,14 +43,8 @@ public:
 	UPROPERTY(EditAnywhere)
 	UStaticMeshComponent* HMDPreview;
 
-	UPROPERTY(EditAnywhere)
-	UStaticMeshComponent* GroundPlane;
-
-	UPROPERTY(EditAnywhere)
-	UMaterialInterface* GroundPlaneMaterial;
-
-	UPROPERTY(EditAnywhere)
-	UNiagaraComponent* GroundVisualizationNiagaraComponent;
+	//UPROPERTY(EditAnywhere)
+	//UNiagaraComponent* GroundVisualizationNiagaraComponent;
 
 
 	float DefaultHorizontalRange;
@@ -80,7 +54,7 @@ public:
 
 	// float determining the distance between the HMD Preview mesh and the BodyPreviewMesh
 	UPROPERTY(EditAnywhere)
-	float HeadBodyDistance = 55;
+	float HeadBodyDistance = 50;
 
 	UPROPERTY(EditAnywhere)
 	UHapticFeedbackEffect_Base* HapticFeedback;
-- 
GitLab