- Home /
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
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..
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.
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.