Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
1 capture
14 Jun 22 - 14 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
1
Question by Lolerooz · Jun 07, 2020 at 10:36 PM · vrcamera-movementjoystickeulerangleslocaleulerangles

Rotating an object taking into account the main camera.

I currently have a script that depending on the joystick axis, rotates the object a certain way, I then send that rotation to the player and orient them on the direction this object is currently facing.

     private void Update()
     {
         h1 = OpenVRController.joystickAxis.x; // set as your inputs 
         v1 = OpenVRController.joystickAxis.y;
         transform.eulerAngles = new Vector3(90f, 0f, Mathf.Atan2(h1, v1) * -180 / Mathf.PI); 
         rotationAngle = transform.eulerAngles - new Vector3(90, 0, 0);
     }

The problem I have is that since I am using eulerangles, if I rotate the camera at all, the way the joystick rotates the object stops making sense in relation to the position of the camera (i.e, If I turn around and press forwards on the joystick, the object points backwards).

I tried using localEulerAngles, and it sorta accomplishes what I want, but since the object is attached to a VR controller, if I rotate the controller, it also rotates the object, which is a no go, since I also need the that the normal of the object I am rotating to stay upwards from the floor.

Is there a way to have localEulerAngles rotate the object while also orienting the object so that it is facing the ground? Or a way to change the script above so that it will take into account camera rotation too?

Thanks in advance!

Comment
Add comment · Show 4
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 Magso · Jun 08, 2020 at 12:02 AM 1
Share

I'm not sure which axis your camera is rotating on but usually you can add the camera's rotation axis' value to the object you want it to affect. However this will cause the object to constantly turn with the camera so if this is not wanted it should only be done when GetAxis() doesn't equal zero for the object's movement.

Show more comments
avatar image cyanspark · Apr 13 at 01:52 AM 0
Share

Add the rotation of the camera to the rotation of the object/player... you can try adding the euler angles of the camera directly, else work with quaternions and add them, which is probably the best way. transform.rotation = quaternion.Euler whatever angles you want to add.

0 Replies

· Add your reply
  • Sort: 

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

173 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

Related Questions

Camera movement Google VR gazePointer 0 Answers

Need help with Quaternions - Making a VR Combination Lock 1 Answer

Look and walk in VR unity 5.6.6 1 Answer

How can I limit the player's camera to move to the edge of the map centering it on the camera? 0 Answers

localEulerAngles has trouble above 87.5 degrees 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