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 MachCUBED · Jun 05, 2012 at 12:32 AM · inputmousecontroller

Problem switching between controller and mouse input

Hi guys,

In my game, you can choose between using a gamepad for your pitch and roll inputs (it's a flight game) and using a mouse. The code for setting the input type works just fine, so my problem is something else. Here's the relevant code:

... roll = Input.GetAxis("Roll") * (Time.deltaTime * rollSpeed) * sensitivity; pitch = Input.GetAxis("Pitch") * (Time.deltaTime * pitchSpeed) * sensitivity; yaw = Input.GetAxis("Yaw") * (Time.deltaTime * yawSpeed) * sensitivity;

         if (controlType == "Mouse")
         {
             roll = Input.GetAxis("Mouse X") * (Time.deltaTime * rollSpeed) * sensitivity;
             pitch = Input.GetAxis("Mouse Y") * (Time.deltaTime * pitchSpeed) * sensitivity;
         }
 ...
 </code>
 </pre>

When the input is set to mouse input, for some bizzare reason, the mouse only controls only control the player's pitch. Switching the axis in the code so that Mouse Y controls roll and Mouse X controls pitch (the opposite of how it should be) doesn't solve the problem, since the mouse still controls only the pitch. I don't think it has to do with anything else in the code, since the player can roll just fine when using a gamepad. In fact, gamepad controls work perfectly. It's baffling, to say the least.

MachCUBED

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bampf · Jun 05, 2012 at 06:10 PM

Here's what I think it is: GetAxis for something like a joystick will give you a displacement value between -1 and 1. According to the documentation, Mouse X and Mouse Y instead give you a delta of mouse movement for that frame, which may require a different formula. I suspect the way you are using the roll value doesn't work with mouse deltas (integers): you are getting multiples of an integer instead of a fraction. For example, if you rotated (360 degrees * roll) then it would look like you were not rotating at all.

Other possibilities: double-check the inputs as defined in the Input Manager. While Mouse X and Mouse Y are given to you by default, I believe they can be edited.

I also note that in the code you posted, yaw gets set regardless of whether mouse or controller is being used. The other two values (pitch and roll) get overwritten by the mouse-driven code, but yaw isn't. So I'm wondering if yaw is interfering with the movement when controlType == "Mouse".

Hope this helps..

Comment
Add comment · Show 2 · 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 MachCUBED · Jun 06, 2012 at 11:53 PM 0
Share

Yaw isn't something that interferes with pitch in my code. Also, I tried increasing the sensitivity of $$anonymous$$ouse X by a huge ammount (0.5 to 100), but that didn't work. $$anonymous$$ouse X still is completely insensitive.

And it doesn't explain why $$anonymous$$ouse Y would work.

avatar image Bampf · Jun 08, 2012 at 11:01 AM 0
Share

Increasing the sensitivity: I don't know why that would help. $$anonymous$$ouse X returns a pixel delta of how far the mouse has moved on the screen. It's not going to return a value between 0 and 1 the way the gamepad will.

And it doesn't explain why $$anonymous$$ouse Y would work.

True, but without seeing how the roll and pitch values are actually used I can't rule it out either. (I suggest posting more details about that.)

Worst comes to worse you'll have to debug the pitch and roll values as the game runs, and formulas that use them, to see what's going on under the hood.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

how to integrate steering wheel controller for ps3 in unity?? 0 Answers

C# Mouse Look (Input.GetAxis("MouseX&Y")) 0 Answers

Implementing a virtual joystick with mouse 1 Answer

Move camera with mouse (2D) 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