Hi I have built a basic HUD to enable me to walk around my level in VR. I have done this by placing both the HUD and the main camera at the same level within my Player object. However if I turn 180 degrees my HUD is now behind me. If I put the HUD inside the camera then I obviously can't get my gazecontrol to ever focus on it since it moves with the camera. I think I want to recentre the HUD as my camera moves, relative to the camera. But I have no idea how to do this. If this is the best solution please can you help? If there is a better solution I am all ears... Code (CSharp): player.position = transform.position + Camera.main.transform.forward * speedSet * Time.deltaTime; HUD.transform.position = player.position; I am building this app without accessing buttons to ensure maximum compatibility thanks for any advice Nick
Well, my first advice would be to abandon gaze control... since Quest came out, there is very little demand for mobile-phone VR, and so the abomination that is gaze control can finally be laid to rest. But even with proper hand controls, you still don't really want UI stuck to the camera except for debugging, as it's just annoying. So yeah, you want it to follow you but in a lazy fashion. You'll do this by (1) getting a Quaternion that matches the camera rotation around the Y axis only; (2) rotating the UI's container towards this at some steady rate, as shown in the example code for Quaternion.RotateTowards.
thanks - i am using Cardboard as this has to work with the cheapest possible hardware, due to the nature of the project. Looking at Quaterion I have tried using this code: HUD.transform.rotation = Quaternion.RotateTowards(HUD.rotation, player.rotation, 5); to no avail Hierarchy HUD Initial setttings When I try to reset position of HUD Player initial settings any ideas? thanks for your help
also when i put a rigid body on the HUD object so I can use this code it starts circling my scene and the movement screen kicks in I am wondering if there is a cleaner approach that achieves the same purpose. Using gaze to move around my scene whilst getting access to the HUD no matter which direction i am facing
You can use Vector3.ProjectOnPlane to remove the pitch up/down from the camera's forward vector and position your UI at the end of that ray. You still have to deal with the fact that you won't be able to gaze at any buttons that are left/right of dead center. Code (CSharp): using UnityEngine; public class FlatForwardDemo : MonoBehaviour { private Vector3 flatForward; private Transform cameraTransform; // Start is called before the first frame update void Start() { cameraTransform = Camera.main.transform; } // Update is called once per frame void Update() { flatForward = Vector3.ProjectOnPlane(cameraTransform.forward, Vector3.up).normalized; var ray = new Ray(cameraTransform.position, flatForward); // world position for UI that's 1.5 meters away from user's face. var endpoint = ray.GetPoint(1.5f); } private void OnDrawGizmos() { if (!UnityEditor.EditorApplication.isPlaying) { return; } Gizmos.color = Color.magenta; Gizmos.DrawRay(cameraTransform.position, flatForward); } }
I assume I'm not the first person to want to walk/stop through gaze ... Is there a standard way to do this? I've a feeling I'm barking up the wrong tree thanks
The best implementation of locomotion via gaze that I've seen was in the GearVR game Land's End. You don't wander randomly. There are marked locations in the world, and you gaze at them to travel to the location. https://www.oculus.com/experiences/gear-vr/940410229366998/?locale=en_US
Thanks... That was my original approach but it increases the risk of motion sickness. By making it based on actual head movement I've found this mitigates the problem (anecdotal but I get it bad on vehicles and fixed path but not when I'm in full control)
so I have gone for four huds as can't work out how to implement the preferred solution; which is fine as this is just a PoC. Code (CSharp): public Rigidbody floor; public Rigidbody player; public GameObject huds; ... ... player.MovePosition(transform.position + Camera.main.transform.forward * speedSet * Time.deltaTime); However when I start to move, the huds don't move with me (the player/camera) - how do i get them to remain in the same place relative to me? thanks