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 chilpert · Apr 18, 2020 at 02:07 PM · rotationtransformgyroscopequaternions

Headlight rotation issue when moving the camera

Hello,

In my game the first player controls the camera using the keyboard. He can make the camera look up and down as well as left and right. The second player uses a phone with a gyroscope to control a headlight. The headlight is a child of the camera, because it's supposed to be a vehicle and a vehicle's headlight always turns with the vehicle itself. Driving straight is not a problem, but as soon as the first player takes a turn, suddenly the gyroscope headlight controller stopps working correctly. Left and right seems to be fine at any time, but up and down gets reversed. Since the code that applies the rotations is scattered in multiple scripts, I will try to give you a short version.

This is the code that rotates the camera (first player):

 if (Input.GetKey("up") || Input.GetKey("w"))
   transform.Rotate(-speedControls * Time.deltaTime, 0f, 0f);
 
 if (Input.GetKey("down") || Input.GetKey("s"))
   transform.Rotate(speedControls * Time.deltaTime, 0f, 0f);
 
 if (Input.GetKey("left") || Input.GetKey("a"))
   transform.Rotate(0f, -speedControls * Time.deltaTime, 0f);
 
 if (Input.GetKey("right") || Input.GetKey("d"))
   transform.Rotate(0f, speedControls * Time.deltaTime, 0f);


This is the code related to the gyroscope (second player):

 // set the headlight's rotation to the gyroscope's rotation
 headlight.transform.rotation = phoneRotation;
 
 // make sure that the headlight is rotating with the camera / vehicle
 headlight.transform.Rotate(-cam.transform.localRotation.eulerAngles);


The first player's input will be handled first, then comes the gyroscope input. The gyroscope input entirely overwrites the first player's input, as seen in the first line. That's why I have added the second line, which is supposed to redo the first player's input.

Comment
Add comment · Show 2
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 TotalPixel · Apr 18, 2020 at 02:30 PM 0
Share

Have you tried using world rotation ins$$anonymous$$d of local?.

avatar image chilpert TotalPixel · Apr 18, 2020 at 04:59 PM 0
Share

Yes, I have tried that as well. The result is very confusing to me. Up and down seems to be not working at all anymore.

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

190 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

Related Questions

quaternion - rotate camera based on original facing at scene start? 0 Answers

Gyroscope Tilting Rotation. Quaternions T_T Help. 1 Answer

Gyro Sensor based on Euler angles? 0 Answers

How can I turn my cube object to the direction it is traveling? 1 Answer

Getting the actual object rotation on just 1 axis 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