Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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.

avatar image Lolerooz Magso · Jun 08, 2020 at 02:47 AM 0
Share

Hey, you were right! I was just overthinking it, turns out that to fix it, all I had to do was add the camera's eulerAngles.y to the rotation of the object, which orients it properly no matter where the camera is pointed.

avatar image IsabelPijnenburg14 Lolerooz · Apr 13 at 11:01 AM 0
Share

thanks for adding that comment, and letting other people know how you fixed it. This was exactly the answer I needed for my problem!

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

AddTorque stops working when model is vertical 0 Answers

Having a main Camera rotate other cameras 2 Answers

Follow rotation of another object but at half the speed 2 Answers

need the game to detect if the analog stick is at the opposite angle 2 Answers

How to rotate my camera? 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