Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by lgorse · Jun 12, 2016 at 08:34 AM · guivrvector3

Place a UI element in the x and z direction of the user's gaze, keeping y value "straight ahead"

I want a UI element to pop up when a user has finished my game. It's a Cardboard game and what I want is for the element to pop up ahead of the viewer, in the direction of his gaze, but only for the x and z values.

IT doesn't make sense to follow the user's gaze's Y-value because I don't want the UI element to pop up on the ground if the user is looking down.

So to summarize: element must appear in the x and z direction the user is looking at, but ignore the y value of the gaze. Instead it should pace the UI element at a fixed height in the x,z direction of the gaze.

I tried the following, but what happens is when the gaze looks down, the UI element get generated not under the user (so it works as expected) but straight in front of him (so that works as expected). But it gets generated really close to the user - right in his face.

Here's my code: CardboardHead head = Camera.main.GetComponent().Head; Canvas endGameObject = (Canvas)GameObject.Instantiate (endGameCanvas);

         Vector3 adjustedHeadDir = new Vector3 (head.Gaze.direction.x, 0, head.Gaze.direction.z);
         Debug.Log (head.Gaze.direction);
         Debug.Log ("head " + adjustedHeadDir);
 
 
         endGameObject.transform.position = adjustedHeadDir*10  + head.transform.position;
         Debug.Log (adjustedHeadDir * 10);
 
 
         endGameObject.transform.LookAt (2*endGameObject.transform.position-head.transform.position);

What I'm not getting is what causes the canvas to show up so close to the user. What causes it to be generated so close to the user when he looks down or up?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mmmpies · Jun 12, 2016 at 04:53 PM 0
Share

What kind of output are you getting from your debug statements?

Would be good to show a look down/forward/up result for each.

avatar image lgorse · Jun 12, 2016 at 10:30 PM 0
Share

@$$anonymous$$mmpies thanks for response.

Attached are 2 screenshots: first one shows meeasurements and debug log when the user faces straight ahead. The placement of the panel is as expected. alt text

Then screenshot 02 shows what happens if the user is looking down. The panel shows up much closer to the head. I'm confused by why, because I expect that by setting y = 0, I'm forcing the direction to be "straight ahead". alt text

Also here is the sample code again- making sure you know where the debugs are called:

 private void showGameOverPanel(){
         CardboardHead head = Camera.main.GetComponent<StereoController>().Head; 
         Canvas endGameObject = (Canvas)GameObject.Instantiate (endGameCanvas);
 
         float $$anonymous$$YValue = $$anonymous$$athf.$$anonymous$$ax (0, $$anonymous$$athf.Abs (head.Gaze.direction.y));
         Vector3 adjustedHeadDir = new Vector3 (head.Gaze.direction.x, 0, head.Gaze.direction.z);
         Debug.Log ("head position " + head.transform.position);
         Debug.Log ("direction: " + head.Gaze.direction);
         Debug.Log ("adjusted: " + adjustedHeadDir);
         Debug.Log ("\n");
     
 
 
         endGameObject.transform.position = adjustedHeadDir*10  + head.transform.position;
 
 
         endGameObject.transform.LookAt (2*endGameObject.transform.position-head.transform.position);
                 
     }


screen-shot-2016-06-12-at-32309-pm.png (331.4 kB)
screen-shot-2016-06-12-at-32337-pm.png (280.0 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by lgorse · Jun 13, 2016 at 03:25 AM

I'm using this hack:

 private float minAllowableDirection(float rawValue){
         if (Mathf.Abs (rawValue) <= 0.2f) {
             if (rawValue >= 0) {
                 return rawValue + 0.7f;
             } else {
                 return rawValue - 0.7f;
             }
 
         } else {
             return rawValue;
         }
 
     }

Basically when the user's gaze goes very low down the X value goes to 0. Any value in the -0.2 to 0.2 range yield to short a distance. So if the value is that low, I adjust for it with what I consider to be an ugly hack - I'm guessing there's a rule here about vectors that I'm forgetting or not finding in the doc, that will allow me to do a better solution. But I'm not finding it.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mmmpies · Jun 13, 2016 at 08:02 AM 0
Share

I was going to suggest getting a point in the forward direction about half way to the ground (or 1 meter as you might be looking up). From that point raycast directly down to get a point on the terrain.

have an empty gameObject at the players feet and get that to look at the point the raycast hits. Then get a point in that direction forward X meters.

A bit convoluted. The alternative is start recording the head look rotation and only instantiate the menu if the player is looking within a set of angles so they're not looking straight down or up.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

100 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trouble With Free Movement & Camera in Oculus 0 Answers

For the HTC Vive How Can I change the SteamVR overlay Menu 0 Answers

GUI mouse just works once 1 Answer

How can I create a VR world space touch-screen input system? 0 Answers

Triggering event at world space GUI using a raycast? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges