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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Floating Menu/inventory

Discussion in 'AR/VR (XR) Discussion' started by kjcvheel, Oct 11, 2017.

  1. kjcvheel

    kjcvheel

    Joined:
    Sep 24, 2017
    Posts:
    3
    So I'm trying to make an inventory for my VR game,
    However, I'm having trouble placing this in my game.
    I know I can attach it to my camera, and see it when I press a button, however, I would like for my inventory to stick to the place im instantaneously looking at when I press the button.

    So I don't want the Inventory to change direction with me while I move the camera. Does anyone know how I could target this problem?

    While writing this I'm thinking, maybe I can keep track of the current position my camera was pointing at and use this to instantiate the inventory screen? Is this do-able, or is there another easier way?

    Any help would be greatly appreciated
     
  2. tomjoe

    tomjoe

    Joined:
    May 11, 2015
    Posts:
    44
    I apologize for the the vague answer, but...
    I would have 3d raycast coming off your headset set the transform.position of the Inventory asset. If you have used a Canvas for your UI, then it would be pretty simple because it already needs to be in world space.
     
  3. AdamAlexander

    AdamAlexander

    Joined:
    Jul 24, 2015
    Posts:
    73
    Hello, sounds like your on the right track. If you want to instantiate your menu some distance in front of your headset you will need to script something like this:

    Code (CSharp):
    1. menu.transform.position = headset.transform.position + headset.transform.forward * 10.0f
    That will place the menu 10 units in front of the headset, no matter which way the headset is facing. You may also need to make the menu face the headset, to do this you will need code like this:

    Code (CSharp):
    1. menu.transform.rotation = Quaternion.lookRotation(headset.transform.position - menu.transform.position)
     
  4. kjcvheel

    kjcvheel

    Joined:
    Sep 24, 2017
    Posts:
    3
    Thanks, This is of great help! I will definitely try this out. Hope I'll get somewhere