Question by
Battered_burrito · May 29, 2018 at 01:44 PM ·
movementcamera-movementmovement scriptplayer movement
SteamVR Movement based on controller direction
Hi, Im trying to get the steam VR camera to move based on the point direction of the controllers. Essentially. If youre pointing right, squeeze the grip, then the camera will move in the direction of the controllers point direction. Regardless of the cameraRigs orientation.
I understand that this causes motion sickness and i appreciate that advice but this is more of an experimental test than anything to get this working for later game elements.
The code i have at the moment is partially "adapted" from a trackpad movemenet system. I just need help filling in the blanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.UI;
using Valve.VR;
public class PointMove : MonoBehaviour
{
// Variable to hold the cameraRig transform values
[SerializeField]
public GameObject cameraRig;
public float Move;
SteamVR_Controller.Device device;
SteamVR_TrackedObject controller;
Vector2 trackpad;
// Stores the axis for the point direction
// Vector2 x+y
// Vector3 X+Y+Z
// Vector4 X+Y+Z+W (Shaders / Mesh tangents)
// Use this for initialization
void Start()
{
// Resets the trackedController Variable and Function to Zero
controller = GetComponent<SteamVR_TrackedObject>();
}
// Update is called once per frame
void Update()
{
device = SteamVR_Controller.Input((int)controller.index);
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
{
// Need to get point location of the controller here
//The trouble movement code below relies on the above and therefore doesnt work atm.
cameraRig.transform.position = new Vector3(cameraRig.transform.position.x + /*Controller Point direction X*/), cameraRig.transform.position.y, cameraRig.transform.position.z + /*Controller Point Driection Z*/));
}
}
}
}
Comment