Skip to content
Snippets Groups Projects
Commit e5f46ab6 authored by Daniel Rupp's avatar Daniel Rupp
Browse files

fix(navigation): fixes pre-travel avatar position

parent 6d4fb12d
Branches
No related tags found
No related merge requests found
Pipeline #408029 failed
No preview for this file type
......@@ -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)
TeleportVisualizer->HMDPreview->SetWorldLocationAndRotation(NewHMDPos, VRPawn->HeadCameraComponent->GetComponentRotation());
// set rotation of bodypreview
TeleportVisualizer->BodyPreview->SetWorldRotation(FRotator(0.0,-90,0));
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)
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());
......
......@@ -2,10 +2,7 @@
#include "UI/TeleportVisualizer.h"
#include "MovieSceneSequenceID.h"
#include "NiagaraComponent.h"
#include "Engine/StaticMeshActor.h"
// Sets default values
ATeleportVisualizer::ATeleportVisualizer()
......@@ -16,8 +13,6 @@ ATeleportVisualizer::ATeleportVisualizer()
RootComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Root"));
Platform = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PlatformMesh"));
//Platform->SetStaticMesh(PlatformMesh);
// disable collisions of platform meshes
FCollisionResponseContainer ResponseContainerPlatform;
ResponseContainerPlatform.SetAllChannels(ECollisionResponse::ECR_Ignore);
......@@ -45,31 +40,25 @@ 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
......@@ -77,12 +66,10 @@ 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(
......@@ -90,17 +77,9 @@ void ATeleportVisualizer::BeginPlay()
EAttachmentRule::KeepWorld,
EAttachmentRule::KeepRelative,false));
//GroundVisualizationNiagaraComponent->SetAsset(GroundVisualizationNiagaraSystem);
GroundPlane->SetMaterial(0,GroundPlaneMaterial);
GroundPlane->AttachToComponent(PreTravelPlatform, FAttachmentTransformRules(
EAttachmentRule::SnapToTarget,
EAttachmentRule::KeepWorld,
EAttachmentRule::KeepRelative,
true));
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*/
}
......
......@@ -100,6 +100,12 @@ public:
void PlayHapticEffect(UHapticFeedbackEffect_Base* HapticEffect, float Intensity);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
private:
UPROPERTY()
UMotionControllerComponent* TeleportationHand;
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment