- Home /
Using Oculus headgear position as input.
I have been trying to use the oculus headgear position as a modifier the speed of a space shooter (chin tucked in means slower speed). However I've run into two problems.
I'm trying to use a script on an empty object to pass on the speedModifier variable to use in other scripts, however it doesn't get any input.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.XR; public class HeadgearModifier : MonoBehaviour { private InputDevice headgear; public float headgearModifier; public float throttle; public float devicePos; public Vector3 deviceVector; void Start() { List<InputDevice> devices = new List<InputDevice>(); InputDeviceCharacteristics headgearCharacteristics = InputDeviceCharacteristics.Camera; InputDevices.GetDevicesWithCharacteristics(headgearCharacteristics, devices); if (devices.Count > 0) { headgear = devices[0]; } } void Update() { headgear.TryGetFeatureValue(CommonUsages.devicePosition, out Vector3 devicePositionValue); devicePos = devicePositionValue.z; deviceVector = devicePositionValue; if (throttle < 0.1f) { headgearModifier = 0.1f; } else if (throttle > 1f) { headgearModifier = 1f; } else if (throttle < 1f && throttle > 0.1f) { headgearModifier = throttle; } } }
This is actually the second method i tried, the first one was simply reference to camera position. however the camera position sometimes got altered somehow (note that i offset the camera to a 3rd person view of the "fighter plane" with the z axis locked (which is the axis i want to use).
public class FollowPlayerX : MonoBehaviour { public GameObject plane; private Vector3 positionOffset = new Vector3(0, 1, -10); void Update() { transform.position = plane.transform.position + positionOffset; } }
If anyone could help me with this i'd be very thankful. Cheers!
I still haven't found the solution to this problem.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Oculus Controller Input only partially working? 1 Answer
Distribute terrain in zones 3 Answers
How to use if statements with New Input System? 1 Answer
C# Touch Script - Fix GameObject touch. 0 Answers