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 Compressed · Jan 20, 2015 at 07:27 PM · c#rotationinputmouse

Rotating object with a mouse movement

Hi, I am trying to achieve mouse controlled rotation of a game object.

I am doing it very simply like this:

 transform.Rotate(Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0);

When the player moves the mouse up and down (Y axis on the screen) the object rotates up and down and the same goes for rotating left and right with X axis.

It works good, but the problem is, I only want the object to rotate up and down and to left and right. However with the solution above the object also rotates on its sides (as in twists). Imagine a shift stick in a car, you can rotate it up and down and to the sides, but you can't grab it and twist it like a screw.

I tried to fix the problem by doing this:

 transform.Rotate(Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0);
 transform.localEulerAngles = new Vector3(transform.localEulerAngles.x,transform.localEulerAngles.y, 0);

The fix worked great, the object rotated up, down, left and right no problem (the twisting bug was gone), but it caused another problem instead, the object was no longer able to rotate lower than 90 degress (or 270 on the opposite side) for some reason.

I am completely out of ideas on how to fix this.

Comment
Add comment · Show 3
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 AcE_fLoOdEr · Jan 21, 2015 at 06:17 AM 0
Share

You know sometimes rotation doesn't work with the mouse. It's like when you try to rotate an object using the rotate tool but then it gets fucked up half way through. I think that's what's happening here.

avatar image AlucardJay · Jan 21, 2015 at 07:44 AM 1
Share

Its called Gimbal Lock : https://www.youtube.com/watch?v=zc8b2Jo7mno

avatar image hav_ngs_ru · Jan 21, 2015 at 02:15 PM 0
Share

@alucardj +1

ScreenToWorldPoint + LookRotation = and you can do it without eulerAngles and it's gimbal lock problem

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Keep objects current rotation, with Input Mouse X 0 Answers

Flip over an object (smooth transition) 3 Answers

Need help on the 3ds max style camera control 0 Answers

Using Input.mouseposition to instantiate 1 Answer

Using quaternion for mouse movement? 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