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 /
avatar image
0
Question by SyntaxTerror · Aug 11, 2016 at 01:21 PM · c#vr

Gear VR movement not working properly.

I'm having some issues with moving around my scenes with Gear VR. I have quite a simple setup where the player taps the touchpad and the camera will move to the location that the player was looking at when they tapped the pad.

It works okay in the editor when I tap the mouse button to simulate the touchpad. However, in Gear VR it moves in a completely different direction to the one requested.

The touchpad is initialised like this:

     void Start () {
         OVRTouchpad.TouchHandler += OVRTouchpad_TouchHandler;
 
         Random.seed = level;
         NewLevel();
 
     }

Input is then handled with a handler:

     private void OVRTouchpad_TouchHandler(object sender, System.EventArgs e)
     {
         OVRTouchpad.TouchArgs touchArgs = (OVRTouchpad.TouchArgs)e;
         OVRTouchpad.TouchEvent touchEvent = touchArgs.TouchType;
 
         switch (touchEvent)
         {
             case OVRTouchpad.TouchEvent.SingleTap:
                 // Move and select things - but only if not already moving
                 if (!isMoving)
                 {
                     Vector3 hitPos = HitSquare();
                     if (!IsWater(hitPos))
                     {
                         // Just move for now
                         MoveTo(hitPos);
                     }
                 }
                 break;
             case OVRTouchpad.TouchEvent.Right:
                 // Create ground
                 // Can't create ground if moving
                 if (!isMoving)
                 {
                     // Work out if it's light green or dark green
                     Vector3 hitPos = HitSquare();
                     Vector2 pos2D = _3DToMap(hitPos.x, hitPos.z);
 
                     if (IsWater(hitPos))
                     {
                         // Place sand at this position
                         Color sand = new Color(1.0f, 0.921f, 0f);
                         map.SetPixel((int)pos2D.x, (int)pos2D.y, sand);
                         map.Apply();
                     }
                     else
                     {
 
                         if (pos2D.x % 2 == 0) // Is even numbered column?
                         {
                             if (pos2D.y % 2 == 0)
                             {
                                 // Is even numbered row, so dark green squares
                                 map.SetPixel((int)pos2D.x, (int)pos2D.y, Color.green);
                                 map.Apply();
                             }
                             else
                             {
                                 // Odd numbered row, so light green squares
                                 map.SetPixel((int)pos2D.x, (int)pos2D.y, new Color(0.194f, 0.905f, 0.194f));
                                 map.Apply();
                             }
                         }
                         else
                         {
                             // Odd numbered column
                             if (pos2D.y % 2 == 0)
                             {
                                 // Is even numbered row, so light green squares
                                 map.SetPixel((int)pos2D.x, (int)pos2D.y, new Color(0.194f, 0.905f, 0.194f));
                                 map.Apply();
                             }
                             else
                             {
                                 // Odd numbered row, so dark green squares
                                 map.SetPixel((int)pos2D.x, (int)pos2D.y, Color.green);
                                 map.Apply();
                             }
                         }
                     }
                 }
                 break;
         }
     }
 

The player looks at an area on the floor and taps the touchpad. The following code does a raycast to get the type of floor tile at the point looked at and stores the destination location. The camera then moves during the update.

     Vector3 HitSquare()
     {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
 
         Physics.Raycast(ray, out hit);
 
         return hit.point;
     }
 
     void MoveTo(Vector3 worldPosition)
     {
         isMoving = true;
         moveDestination = worldPosition;
         GameObject camContainer = GameObject.Find("CameraContainer");
         moveDestination.y = camContainer.transform.position.y;
     }
     
 
 
 void Update () {
     
         if (isMoving)
         {
             GameObject camContainer = GameObject.Find("CameraContainer");
             float step = Time.deltaTime * moveSpeed;
             camContainer.transform.position = Vector3.MoveTowards(Camera.main.transform.position,
                 moveDestination, step);
 
             if (camContainer.transform.position == moveDestination)
                 isMoving = false;
         }
     }

Like I said, it works fine in the editor but the camera moves off to a completely different direction in Gear VR.

Comment
Add comment · Show 1
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 SyntaxTerror · Aug 11, 2016 at 02:56 PM 0
Share

I finally figured it out. The ray cast needed to be from the camera, not the mouse position. I forgot that there is no mouse pointer with the Gear VR.

There is another issue, though. The track the camera moves along from point A to point B isn't accurate. The final position is fine but for some reason the track it takes to get to point B is slightly off but it then corrects itself as it nears the target position, resulting in a last $$anonymous$$ute arc to the left or right. A bug in the Vector3.$$anonymous$$oveTowards function?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by youngwolf0 · Jun 01, 2017 at 02:16 PM

I'm assuming you're using the OVRPlayerController, have you attached your script to the CenterEyeAnchor? If not you can't guarantee you'll teleport to the correct spot. The other possibility I can think of is that you may have inadvertently rotated one of the nested components in the controller meaning your camera is not facing the direction you think it is. I'm not an expert with this but have just implemented a similar system and those were the issues I hit on.

Comment
Add comment · 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

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

215 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 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 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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Manipulating the location of the VR controllers (Vive/SteamVR) in script 0 Answers

How to detect which button a SteamVR action is bound to? 0 Answers

How to disable position and rotation measurement from VR headset gyroscope? 2 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