Joystick Axis

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 ?

For joystick buttons you need to use Input.GetButton instead: Unity - Scripting API: Input.GetButton

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.

Can you post a snippet of your code? Sounds like you’re doing something wrong.

Sure, I just check if the button is pressed with a print command for now, I still can’t make the joystick work:

print(Input.GetButton("JoystickTest"));

I’ve attatched a picture of the input settings below

440254--15308--$joystick.png

Try changing the Gravity to 1000, Dead to 0.001 and Sensitivity to 1000 in the input settings.

Done, it still doesn’t work. Have you ever set up a joystick? And if yes, do you remember having to do something speciffic?

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…

http://trust.com/products/productmanuals.aspx?artnr=15431

This is my gamepad, maybe the problem is in it.

Could be, do you have any other apps (or utilities) to test the joystick?

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.

Well, that’s what I ment by:

So I’ve tried everything? That’s odd…

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.

Yeah, I’m with 3.1

Did you have your joystick plugged in / enabled / wiggled the joysticks before starting Unity?

I’ve been having an issue where Unity 3 ignores my joysticks if they’re plugged in or turned on after starting the Unity editor.

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 :slight_smile:

Sounds like your joystick might not be “hot plug-able”? I’ve been using a Logitech Rumblepad 2 for years and it’s always worked perfectly with Unity.

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.