I’ve been reading the documentation about the input very carefuly and also read several topics about that, but I still can’t get it to work. I want to enable joystick support for my game. I don’t want to be switched between the joystick and the keyboard from a menu, I just want a joystick alternative. The problem is that the joystick doesn’t get detected for some reason.
For example:
print(Input.GetKey(KeyCode.JoystickButton1));
Will output false all the time, no matter what button I press. The joystick itself is working with other games, so the problem shouldn’t be in it. So can you help me with this one? Seriously, I couldn’t find a lot of topics about joysticks.
And the other thing that is bothering me, though I haven’t sill gotten the joystick to work:
How will I set an Input axis, so that it could be controlled either by the keyboard or the Joystick ?
To handle both joystick and keyboard input at the same time, you just need to have two settings set up for the same input. Look at the default input manager settings and you’ll see what I mean.
Thanks, but it’s still not working, I created a new input with positive number joystick button 4and set to type Key Or Mouse Button Pressed. The game doesn’t detect it. And I have looked into the default settings, but I couldn’t find exactly what I was looking for. I want to analog sticks to walk and look arround and for my movement input I have a positive and a negative buttons from the keyboard mapped, but the analog sticks aren’t buttons and I don’t know how will I go for this.
I’ve set up joysticks many times. The only other thing I can see in the input settings is that I have “Axis” set to “X axis” and I typically use code like this to call it:
function Update () {
if (Input.GetButton("JoystickTest")) {
print ("joystick button pressed");
}
}
Damn, it still doesn’t work. I switched USB ports, used different button numbers, set the Joy num to different numbers, usd Joystick axis for type… in the input - nothing works…
Well, the nly game on my PC, that uses a joystick is Mountain Bike Adrenaline (don’t have a lot of games really). It also works great with my PS3, though it doesn’t have that PS middle button, which the PS3 joysticks have.
I downloaded this tester: http://wareseeker.com/download/joystick-tester-1.0-build-010000.rar/404159
And everything was ok, every single button worked, so I’m all out of ideas. Great.
The only other things I can think of is to try it with different joystick button labels, ie. “joystick button 2”, “joystick button 1”, etc. It could be the label on the joystick is different than the number Unity assigns it. I’m assuming you’re using Unity 3.1, right? Not that it should matter but I know someone else had issues with Unity 3.1 and joystick raw input.
Everything I can think of, but I’m juggling a couple projects at the same time so I could be missing something. Are you using 3.1? I’m dealing with a computer with hard drive issues at the moment otherwise I’d create a sample project for you to test.
Well, all day yesterday I had my joystick plugged and I restarted Unity several times and it didn’t work, but today, everything works… pretty strange. So thank you for your time, guys! I still can’t set up the axes right, but once my joystick is working, it shouldn’t be impossible
Maybe, I wasn’t aware of that fact. I remember that I pluged the joystick after starting my computer and before running Unity. Well, in that case, it shouldn’t have worked with the other game and the tester, right ? That was something weird. Anyway it’s fixed now.
I just have a little scripting question. I can’t use one input for the keyboard and the joystick if I want to use it as axis (I want to use the analog sticks). So I’ll have to create a new movement inputs for the joystick. The question is then how would I get the value of the joystick and the keyboard at the same time without them summing or multiplying?
Yeah, you’re right about the hot-plug-able joystick. If it worked in your test app and you launched Unity after it was plugged in, it should have worked.
Look at the default settings for input. It’s a good example of how to set up for joystick and keyboard input.