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 Ereptor · Apr 14, 2016 at 08:23 PM · androidlerpvirtualrealitylocalrotation

Set Local Rotation of VR Camera Rig

Hi Everybody,

I have a first person environment that I am building a custom navigation for with Gear VR and a MOGA controller. I have built the navigation to do the following:

  1. The left stick strafes the player forward, backward, left, and right according to the player's BODY orientation.

  2. The right stick left and right inputs rotate the player's BODY left and right, respectively.

  3. The Gear VR controls the head movement of the player (we are assuming the player has owl-like head movement).

  4. There is an indicator attached to the player's field of view that tells them which direction their body is facing.

  5. When the player begins to strafe forward or backward, the camera lerps to align with the body. This means that if they specifically want to go the direction they are facing, their body will cooperate and turn around.

The problem is, while I can use a lerp to set my normal main camera's rotation to match my body's rotation, I can't seem to set my VR camera's rotation to match my body's rotation. When I attempt to rotate the VR camera using camera.main, or any reference to camera.main, nothing happens. When I attempt to use UnityEngine.VR.InputTracking I have the option to GetLocalRotation but not SetLocalRotation and I don't seem to be able to use the two interchangeably.

If I manually make a parent to the camera, the camera's parent's local rotation doesn't give me any data on where the VR camera is facing that I can use to start a lerp. If I manually apply the lerp to a child of the camera, it won't rotate the parent.

How do I do the following to my VR camera?

 _startHorizontalRotation = _playerTransform.rotation.eulerAngles.y;
 _endHorizontalRotation = _cameraTransform.rotation.eulerAngles.y;

 _startLocalHorizontalRotation = _cameraTransform.localRotation.eulerAngles.y;
 _endLocalHorizontalRotation = 0.0f;

 Vector3 _startLocalVector = new Vector3 (0, _startLocalHorizontalRotation,0);
 Vector3 _endLocalVector = new Vector3 (0, _endLocalHorizontalRotation, 0);

 Vector3 counterLerpCamera = Vector3.Lerp (_startLocalVector, _endLocalVector, percentageComplete);
 _cameraTransform.localRotation = Quaternion.Euler (counterLerpCamera);

In the editor, this spins the player's body to their head direction while resetting their head direction to a local rotation of 0 on their body. Works perfectly, but I lose the ability to rotate the camera when switching to VR mode.

This is the important line that needs to change:

 _cameraTransform.localRotation = Quaternion.Euler (counterLerpCamera);

Where _cameraTransform.localRotation needs to set the VR camera rig's local rotation.

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 dsrgdeg · Jun 05, 2016 at 07:19 PM 0
Share

Hi @Ereptor. I've been trying to integrate $$anonymous$$oga controller in Unity 5. The sample asset is throwing null reference and null ptr errors. Did you face the same ? There is hardly any support from $$anonymous$$oga for their sdk.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mptp · Apr 15, 2016 at 01:48 AM

I don't fully understand - there seems to be a contradiction in having the left stick strafe relative to the body, but lerping the body rotation to head direction when you strafe. Why not just have strafe relative to the head direction?

But if you did want to do it that way for some reason, perhaps you could just store a logical y-rotation as a float and have the camera not rotate the parent object. The right stick will just add or subtract from this rotation, and the left stick move the camera along the orthogonal directions rotated by the logical rotation. Then, when you strafe, you get the head rotation's y component and lerp your rotation float to that value.

Comment
Add comment · Show 3 · 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 Ereptor · Apr 18, 2016 at 11:19 AM 0
Share

I've been demonstrating movement styles in waves. I figured the most elegant solution was to have forward be the camera facing direction, but this wasn't what the user had in $$anonymous$$d. Aligning strafe to a constant position also wasn't the intended result, so we added a body rotation. This solved all of the client's needs except the fact that they still got confused when they were looking in a new direction and forgot to realign their body before moving forward, so I'm trying to solve that by just doing it for them when they are turned around.

It's convoluted, but it works for our purposes. For now what I'm planning to do is implement a mid-level parent (calling it a 'neck' informally) that will actually serve as my grabbable rotation handle on the camera. The only problem with this solution is that the neck will always be out of alignment with the head and body, and I'll have to test the camera and body's rotation separately ins$$anonymous$$d of getting a relative rotation.

avatar image Ereptor · Apr 18, 2016 at 12:49 PM 0
Share

I'm still greatly struggling with manipulating a mid-level parent in a simple way. I'll see if I can do the y-rotation float route.

avatar image Ereptor Ereptor · Apr 18, 2016 at 12:56 PM 0
Share

The problem remains, though, that rotating the camera's parent also rotates the camera; however, I can't rotate the camera itself. In order to make the camera "stand still", I need to be able to grab something related to the camera and rotate it opposite of the body.

There needs to be a rotation and a counter-rotation in order for the camera to stay in the same place.

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

63 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

Related Questions

Unity app not running in Android phone. 0 Answers

GearVR wont initialize the scene (working fine in Editor) 0 Answers

How can i run a Unity Build on my PC, but use my phone as second screen, (Cheapskate Oculus-Like) 2 Answers

Speech Recognition for Android (For Beginner) 0 Answers

VR app spins uncontrollably on iOS 14 (Unity 2019.4.11) 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