diff --git a/Content/Components/Movement/Teleportation/BP_TeleportationComponent.uasset b/Content/Components/Movement/Teleportation/BP_TeleportationComponent.uasset index d924129f28babb468384a1d11df4dd09f7fa173b..84af73944a752da2e002f5f6cb733d64ffbd855b 100644 Binary files a/Content/Components/Movement/Teleportation/BP_TeleportationComponent.uasset and b/Content/Components/Movement/Teleportation/BP_TeleportationComponent.uasset differ diff --git a/Source/RWTHVRToolkit/Private/Pawn/Navigation/TeleportationComponent.cpp b/Source/RWTHVRToolkit/Private/Pawn/Navigation/TeleportationComponent.cpp index c2ea22ca7ebd2d3b10742f5004890f4a619545e1..5a0b76685823fa4418af86149cb63dc76bccc800 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 4d4fd2e45251e0f07932884d293664aeb645da62..1fe58e684e856b9e19fa5519eac40da7851eadbb 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 5b8db18fc9ac2d14a985716d5f62b20ca4bf2f6c..fffded4a32189bba5ec9253921cfd3c2dc2ce56f 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 85f164cd02535ff0864f69aa870bdaa1f1c2c379..7fac1ad355ed1684d73ec886fdc18c7a131e9876 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;