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 FirstTimeUnited · Jun 01, 2013 at 07:03 AM · rotationtransform

Camera controller makes camera involuntary rotate around local z-axis

Used this code found here http://unity3d.cba.pl/Documentation/Documentation/ScriptReference/Input.GetAxis.html

 float h = horizontalSpeed * Input.GetAxis("Mouse X");
 float v = -verticalSpeed * Input.GetAxis("Mouse Y");
 
 transform.Rotate(v, h, 0f);


It works. But if I move the cursor in circles the camera slowly rotates around it's local z-axis tilting the world view. The camera is otherwise stationary.

Does anyone know what to do to rectify this? All help is appreciated.

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 fueldown · Jun 02, 2013 at 12:27 PM

use

 transform.Rotate(v, h, transform.rotation.z);

OR

 transform.rotation += Quaternion.Euler(v, h, 0f);
 

instead. You are changing current rotation along z axis to 0f, which is not correct.

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 FirstTimeUnited · Jun 02, 2013 at 02:25 PM 0
Share

Thanks, but that didn't work.

Have allready tried:

 transform.Rotate(v, h, transform.rotation.z);

That just keeps the camera spinning around the local z-axis even after I stop moving the cursor in circle

The latter:

 transform.rotation += Quaternion.Euler(v, h, 0f);

Didn't work, at least not for C# and I don't think the += operator is overloaded for quaternions. But I figured it was supposed to be the same as:

 transform.rotation *= Quaternion.Euler(new Vector3(v, h, 0f));

Unfortunately this didn't work either. The camera still rotates around local z-axis.

avatar image FirstTimeUnited · Jun 02, 2013 at 05:22 PM 0
Share

Edit:

Acutally:

 transform.Rotate(v, h, transform.rotation.z);

doesn't keep the camera spinning, but spins it back to it's 0 rotation on the z-axis over several seconds. This is still not what I want tough. I want it to not spin around the local z-axis at all.

avatar image fueldown · Jun 03, 2013 at 03:09 AM 0
Share

my bad with += . I was actually wanted to say *=. Anyways, looks like you got your answer.

avatar image
0

Answer by FirstTimeUnited · Jun 02, 2013 at 08:11 PM

Well looks like I finally found the answer. The problem is gimbal lock apparently. All though I thought one of the advantages of using quaternions was to avoid gimabl locks.

If anybody else has this problem use the code posted on the following link. It worked for me. He also explains the problem.

http://answers.unity3d.com/questions/172728/transfromrotate-changes-z-axis-incorrectly.html

Sidenote: Find it weird that gimabl lock is not mentioned in the official documentation for Input.GetAxis(see link at top of post). My code was taken directly from there and didn't work. If we can't rely on the creators of the game engine who can we rely on?

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

15 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

Related Questions

Rotating An Object On Its Axis Once 3 Answers

2D Camera Rotation Along Level Boundaries 1 Answer

transform.rotation doesn't stop 1 Answer

How can I rotate an object towards the mouse in only one axis? 1 Answer

rotation script in unity 3 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