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 stilahun · Jul 27, 2016 at 07:15 PM · cameravrtranslationcoordinate-system

Unity/SteamVR changing coordinate system based on camera view

Hello,

I am trying to get started with developing VR in unity using an HTC Vive and the SteamVR plugin. I am able to see everything in VR and translate it using controllers, but the coordinate system is very confusing. The object only goes right when I press the right touchpad when it is oriented a certain way. Once it is rotated differently, its axes are no longer in line with its initial ones. Also, if I move in the scene using the headset tracking, the coordinate system obviously doesn't move. This means that I can press right and it will go "forward".

I looked into some coordinate system changes such as WorldToViewportPoint to try and make the coordinate system the same as the camera, but to no avail (I am not sure if this is even possible, or if it didn't work because I executed it incorrectly). I also looked into making the model I am trying to translate a child to the camera attached to the headset, as well as the other way around. Nothing worked as I imagined. I am obviously new to C# and Unity, so I do not know many intricacies of things like this.

using UnityEngine; using System.Collections; using System.Reflection; using Valve.VR;

[RequireComponent(typeof(Camera))] public class MonoBehaviour { public class conrotate : MonoBehaviour {

 public GameObject head; 
 public GameObject testhead;
 SteamVR_TrackedObject trackdeObjec; 
   Camera headCam;
 void Awake()
 {    
     //获取手柄上的这个组件    
     trackdeObjec = GetComponent<SteamVR_TrackedObject>(); 
         // headCam = head.GetComponent<Camera>();
 }    
  

 //void Start () {

 //}
     

 uint i; // iterative counter

 void FixedUpdate () {
     var device = SteamVR_Controller.Input ((int)trackdeObjec.index);  
     float translation = Time.deltaTime * 10;
     float t =Time.deltaTime/100;
     //translation
     if (device.GetPress (SteamVR_Controller.ButtonMask.Touchpad)&&(!device.GetPress (SteamVR_Controller.ButtonMask.Trigger)))
     {       
         Vector2 ccc = device.GetAxis ();      
         float angle1 = VectorAngle (new Vector2 (1, 0), ccc);    

 

         if (angle1 > 45 && angle1 < 135) { 
             
             // Vector3 viewPos = headCam.WorldToViewportPoint(transform.position);
             // Debug.Log (testhead.transform.position);
             // Debug.Log (viewPos);
             testhead.transform.Translate(Vector3.up*-translation,Space.World);
             Debug.Log ("down");    
         }    

This is just an example of what I attempted with the WorldToViewportPoint. Everything commented out is my attempt. I do not know if I am using it correctly or not. I can get the Debug.Log to show "viewPos" (at least sometimes) and it has different coordinates, but the translation remains the same. The coordinates also go above 1 and below 0, which I think is strange for Viewport.

TL;DR I want to change the axes on an object to be those used by the VR camera on the headset so when I press right it always goes right relative to what I am seeing. I have no idea if this is possible, nor how to do it. Send help please, anything is appreciated. Thanks in advance.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by danilogasques · Jun 29, 2017 at 07:06 PM

It seems that you are looking for the forward direction of your headCam transform. Take a look at the documentation here: https://docs.unity3d.com/ScriptReference/Transform-forward.html

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

VR app controls are inverted 0 Answers

How to get smooth device camera in gearvr like passthrough option? 0 Answers

How to open the resources from a downloaded game to add another viewpoint? 0 Answers

Scissor test/early rejection 2 Answers

How to attach camera to player in a right way 1 Answer


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