Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 pajamajama · Jul 18, 2013 at 08:17 PM · scriptingbasicsscriptingproblem

Fixing Inverted Camera Controls When Flipped, MouseOrbit

Hello, thank you very much for any help you can provide.

I'm using a script called MouseLook. It's very similar to MouseOrbit, that comes with Standard Assets. I attach MouseLook to my camera and set the Ymin to -360 and the Ymax to 360. My target object is a sphere. This now enables me to rotate infinitely in any direction around the sphere. All good so far.

The problem I'm having is when the camera flips upside down, my 'Left/Right' controls become inverted. So instead of moving mouse left to move camera left, moving mouse left moves the camera right. I want to fix the controls so that they are always consistent visually.

My guess is the logic should be something along the lines of, "If camera is upside down: invert Left/Right controls", and that should cancel out the effect this is having. Unfortunately my scripting/math skills are very beginner.

Here's where I'm at:

 zRotation = GameObject.Find("Main Camera").transform.rotation.eulerAngles.z;
         
         if (axes == RotationAxes.MouseXAndY)
         {
             if (zRotation == 180){
                 
             // Read the mouse input axis
             rotationX += Input.GetAxis("Mouse X") * sensitivityX;
             rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
 
             rotationX = ClampAngle (rotationX, minimumX, maximumX);
             rotationY = ClampAngle (rotationY, minimumY, maximumY);
             
             Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
             Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
             
             transform.localRotation = originalRotation * xQuaternion * yQuaternion;
             }
             else{
             
             Debug.Log (zRotation);
             
             
             // Read the mouse input axis
             rotationX += Input.GetAxis("Mouse X") * sensitivityX;
             rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
 
             rotationX = ClampAngle (rotationX, minimumX, maximumX);
             rotationY = ClampAngle (rotationY, minimumY, maximumY);
             
             Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
             Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
             
             transform.localRotation = originalRotation * xQuaternion * yQuaternion;
             
             }

if "zRotation" == 180, than I know my camera is flipped. But I'm having a hard time understanding the code at that point. What's a good way to flip the controls?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by bubzy · Jul 19, 2013 at 05:57 AM

  if (zRotation == 180)

this condition only works when the angle is EXACTLY 180. you will want to change this to something like

  if (zRotation >= 180)

for all angles including and exceeding 180. you can then use something like

  rotationX += -Input.GetAxis("Mouse X") * sensitivityX;
  rotationY += -Input.GetAxis("Mouse Y") * sensitivityY;

to invert the input values.

Comment
Add comment · Show 1 · 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 pajamajama · Jul 19, 2013 at 07:12 AM 0
Share

Thank you Bubsy, but it seems that this is now preventing me from rotating to a certain degree.

The reason i chose to use zRotation == 180, is because for some reason my zRotation is always < 180 when the camera is right side up, and always == 180 when it is upside down. For some reason It never is > than 180. $$anonymous$$aybe that's a clue! Anyways, thank you again for your help. I really hope we can figure this out.

avatar image
0

Answer by gooncorp · Jun 26, 2014 at 05:51 PM

Did you seriously get that to work? Don't these values need to scale?

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

17 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

Related Questions

Trying to find the highest number than add it to itself. 2 Answers

variables within variables? 2 Answers

Animator Controller 0 Answers

Junior Programming Pathway scaling a cube 2 Answers

Issue with animation and gravity. 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