Steamvr探索(2)_实现瞬移和自由移动的功能

一、瞬移功能

瞬移功能网上的例子挺多的,我就不多赘述了,在此附上一个例子,按着做就能实现瞬移:https://blog.csdn.net/Czhenya/article/details/78483099。
这里有一个地方需要说明一下,从商店里下载steamvr插件之后在导入瞬移插件,在瞬移插件脚本里会报错,是缺少命名空间的引用,没有过多的研究,我的方法是不要导入unity商店里的steamvr插件,直接导入瞬移插件即可点击下载插件

二、自由移动

这个功能也挺简单,这个功能是接着上一篇文章写的,如果看不懂就看一下我的上一篇文章,挺简单的直接上代码。把这个类直接放在Player上就可以。

在这里插入图片描述

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class SLQPlayerController : MonoBehaviour {

    //头
    public Transform head = null;

    //头的父节点
    public Transform headRoot = null;


    private NavMeshAgent navMeshAgent = null;

	// Use this for initialization
	void Start () {

        navMeshAgent = GetComponent<NavMeshAgent>();
		
	}
	
	// Update is called once per frame
	void Update () {

        // print(hand.forward);

        //可以一直向着眼镜看的方向移动
        transform.rotation = Quaternion.Euler(0, head.transform.rotation.eulerAngles.y, 0);
		
	}

    private void OnEnable()
    {

        SLQHandGripController.SLQTouchDataEvent += SLQHandGripController_SLQTouchDataEvent;
    }

    private void OnDisable()
    {
        SLQHandGripController.SLQTouchDataEvent -= SLQHandGripController_SLQTouchDataEvent;
    }

    private void SLQHandGripController_SLQTouchDataEvent(Vector2 _vec2)
    {
        //自由移动
        //if (_vec2.x > -0.5f && _vec2.x < 0.5f && _vec2.y > 0.5f)
        //{
        //    navMeshAgent.SetDestination(transform.position+transform.forward);

        //    handRoot.position = transform.position + transform.up;
        //}
    }



   
}
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值