Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Select button following Camera head rotation

Discussion in 'AR/VR (XR) Discussion' started by reddo, Feb 19, 2018.

  1. reddo

    reddo

    Joined:
    Jul 1, 2015
    Posts:
    39
    I'm using this script to get a row of 3 buttons to follow with the camera/head movement.

    Code (CSharp):
    1. public class FollowCamRotation : MonoBehaviour {
    2.     public GameObject cam;
    3.     public float speed = 0.5f;
    4.     private Vector3 v3Offset;
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.         v3Offset = transform.position - cam.transform.position;
    9.  
    10.     }
    11.    
    12.     // Update is called once per frame
    13.     void Update () {
    14.         transform.position = cam.transform.position + v3Offset;
    15.         transform.rotation  = Quaternion.Slerp (transform.rotation, cam.transform.rotation, speed * Time.deltaTime);
    16.         transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y, 0);
    17.     }
    18.  
    19. }
    The set of buttons rotates fine but I can only gaze select the center button. The left and right buttons are hard to select because once the head/camera is moved the set of buttons follows to the center again.

    Is there a way to get the set of buttons not to follow head movement in a certain range while near the camera center position so the left and right buttons can be selected?
     
  2. Selzier

    Selzier

    Joined:
    Sep 23, 2014
    Posts:
    652
    I did this in my pack 360 Video Player, I spawn the menu when the player looks at it, and delete the menu when player looks away.

    For a simple solution, try making a box collider which covers all the buttons.
    - OnPointerEnter, set the parent of the menu to null.
    - OnPointerExit, set the parent of the menu to the Main Camera.
     
  3. reddo

    reddo

    Joined:
    Jul 1, 2015
    Posts:
    39
    Thanks for the info. Will give the parent solution a go.

    EDIT: The box collider did the trick. Cheers.
     
    Last edited: Feb 20, 2018