大家都知道在U3D瞬移很好做,用steamvr提供的脚本或者用VRTK加上寻路网格就可以轻松完成
那么在UE4中呢
下面我们共同研究一线 在UE4中如何利用寻路网格做vr瞬移
首先构建一个C++类继承于SceneComponent类
我将其命名为RunebergVR_Teleporter
讲头文件改为
include “Components/ActorComponent.h”
include “Components/SplineComponent.h”
include “Components/SplineMeshComponent.h”
include “RunebergVR_Teleporter.generated.h”
为了省事。。额。。我还是决定上代码吧
头文件如下利用SplineMesh的特性形成弯曲的曲线,在CPP中实现具体实现原始点到终点的弯曲
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "Components/ActorComponent.h"
#include "Components/SplineComponent.h"
#include "Components/SplineMeshComponent.h"
#include "RunebergVR_Teleporter.generated.h"
UENUM(BlueprintType)
enum class EMoveDirectionEnum : uint8
{
MOVE_FORWARD UMETA(DisplayName = "Towards Player"),
MOVE_BACKWARD UMETA(DisplayName = "Away from Player"),
MOVE_LEFT UMETA(DisplayName = "Left of Player"),
MOVE_RIGHT UMETA(DisplayName = "Right of Player"),
MOVE_CUSTOM UMETA(DisplayName = "Use a Custom Rotation for Direction")
};
UCLASS(ClassGroup = (VR), meta = (BlueprintSpawnableComponent))
class VRTELEP_API URunebergVR_Teleporter : public USceneComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
URunebergVR_Teleporter();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
// The teleport beam's mesh
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Beam Parameters")
class UStaticMesh* TeleportBeamMesh = nullptr;
/** The teleport beam's Launch Velocity Magnitude - higher number increases range of teleport */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Beam Parameters")
float BeamMagnitude = 500.f;
/** A location offset from the parent mesh origin where the teleport beam will start */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Beam Parameters")
FVector BeamLocationOffset = FVector::ZeroVector;
/** For ray type beam, ensure the lenth of the beam reaches target location instantenously. Uses RayScaleRate as base length unit */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Beam Parameters")
bool RayInstantScale = true;
/** How much the ray will scale up until it reaches target location */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Beam Parameters")
float RayScaleRate = 1.f;
/** The teleport beam's navigation mesh tolerance - fine tune to fit your nav mesh bounds */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Beam Parameters")
FVector BeamHitNavMeshTolerance = FVector(10.f, 10.f, 10.f);
/** The teleport beam's custom gravity */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Beam Parameters")
float ArcOverrideGravity = 0.f;
// The teleport target stuff
/** Additional offset of pawn (internal offsets are Steam: 112, Rift: 250) */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Target Parameters")
FVector TeleportTargetPawnSpawnOffset = FVector(0.f, 0.f, 0.f);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Target Parameters")
float FloorIsAtZ = 0.f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Target Parameters")
class UStaticMesh* TeleportTargetMesh = nullptr;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Target Parameters")
FVector TeleportTargetMeshScale = FVector(1.f, 1.f, 1.f);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Target Parameters")
FVector TeleportTargetMeshSpawnOffset = FVector(0.f, 0.f, 5.f);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Target Parameters")
class UParticleSystem* TeleportTargetParticle = nullptr;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Target Parameters")
FVector TeleportTargetParticleScale = FVector(1.f, 1.f, 1.f);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR - Teleport Target Parameters")
FVector TeleportTargetParticleSpawnOffset = FVector(0.f, 0.f, 0.f);
/** Check to see if an active teleport mode is turned on */
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "VR - Read Only")
bool IsTeleporting = false;
// Show the teleportation arc trace
UFUNCTION(BlueprintCallable, Category = "VR")
bool ShowTeleportArc();
// Show the teleportation ray trace
UFUNCTION(BlueprintCallable, Category = "VR")
bool ShowTeleportRay();
// Remove the teleportation arc trace
UFUNCTION(BlueprintCallable, Category = "VR")
bool HideTeleportArc();
// Remove the teleportation ray trace
UFUNCTION(BlueprintCallable, Category = "VR")
bool HideTeleportRay();
// Show marker in the world
UFUNCTION(BlueprintCallable, Category = "VR")
bool ShowMarker();
// Move Marker
UFUNCTION(BlueprintCallable, Category = "VR"</