UE4 VR 瞬移 Teleport 一

大家都知道在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"</
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值