Table of contents
Import steamVR packages and settings
Opening introduction
steamVRWe useHTC as an example, the same is true in the official sample Ray teleportation movement, we will not go into details first, only the key movements will be discussed, andPicoXR’s joystick movement It’s different,HTC moves more like a disc
But it is different, but it is also the same. Same This is a Vector2 value, divided into x and y, and the range is [-1,1]
Import steamVR packages and settings
1. First we need to download steamVR from the Unity store, which is free, SteamVR Plugin< /span>
2. ImportsteamVR package,Window→Package Manager→Packages: My Assest→Then we Search steamvr download and import it
3. Set up steamVR Input, Window→SteamVR Input, we add one in Action, name it TeleportV2, and set the type to Vector2 ,Save it for the last time. If you don’t understand, you can watch the video
Finally we clickOpen binding UI and put this value on the disc of the handle
Note: The disk is Teleport. You can check other experts' methods first. Remember to connect the device and download steamVR. It is also free in the steam store.
code
Finally we write the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;//steamvr
public class Player : MonoBehaviour
{
Quaternion my_head;//头朝方向,也就是移动方向
void Start()
{
my_head = Quaternion.Euler(0, Camera.main.transform.eulerAngles.y, 0);
}
void Update()
{
SteamVR_Move();
}
public float speed=5;
public CharacterController character;
void SteamVR_Move()
{
Vector2 my_padPosition = SteamVR_Input.GetAction<SteamVR_Action_Vector2>("TeleportV2").axis;//获取自己定义的圆盘Vector2值
Vector3 dirction = my_head * new Vector3(my_padPosition.x, 0, my_padPosition.y);//类似xr的
//transform.position += dirction*Time.deltaTime*speed;//和上一期一样
character.SimpleMove(dirction * speed);
}
}
Note: using Valve.VR; must be added. For some API introductions to steamVR, you can check out other experts’ posts.