Game Development Community

How do I get a Joystick working? Please help

by Dan T. · in Torque Game Builder · 09/29/2006 (4:10 pm) · 9 replies

Hello, All.

I've followed all the documentation trying desperately to get my joystick to work with Torque 2D but with no success. Here is my code...

new ActionMap (XboxPad);
enableJoystick();
enablemouse();
XboxPad.bind(joystick0, "button0", toggleU);
//XboxPad.bind(mouse0, "button0", toggleU);
//XboxPad.bind(keyboard, "u", toggleU);
XboxPad.push ();

I have three lines that I "//" in and out to test the functionality.
Keyboard works fine and calls the function.
Mouse and Joystick do nothing.

Any suggestions?

Does anyone know a really good tutorial?
Or perhaps have a code example?

Thanks,
Dan.

PS If anyone knows how to apply a rotational force (not velocity) that would be ahndy too, thanks!

#1
10/01/2006 (1:14 am)
If you're using DirectInput, you'll need one extra bit before enableJoystick()

$enableDirectInput = true;
activateDirectInput();

Naturally, the above is Windows only.
#2
10/02/2006 (12:08 am)
Thanks - that wsan't in the manual! :(

I tried this last night and it works...
but only when I test the game in the editor!
When I compile my game an run it the controls don't respond.
Any more ideas?

Thanks again for your help.

Yours,
Dan.
#3
10/02/2006 (6:31 am)
Hmm, I haven't tried compiling before, to be honest. :\
Not really sure why it wouldn't work on compile.
#4
10/12/2006 (8:22 am)
Dan, if you're still having trouble, I have a little sample project I built to figure out the basics of using an X-Box 360 joypad with TGB.
#5
10/23/2006 (12:42 pm)
I would like to see this example app as a game I am making would be killer to use the joypad.

thanks
#6
10/28/2006 (10:09 am)
I have a weird problem with my joystick where the buttons work but the directionals controls dont work ....have a sample any suggestions????


GlobalActionMap.bindCmd(joystick, "up", "playermoveup", "");
GlobalActionMap.bindCmd(joystick, "down", "playermovedown", "");
GlobalActionMap.bindCmd(joystick, "left", "playermoveleft", "");
GlobalActionMap.bindCmd(joystick, "right", "playermoveright", "");
#7
10/28/2006 (10:45 am)
Which directional controls are you trying to use: the dpad, or the left analog stick? Both of these will use a different set of inputs.

For the dpad, you'll be using:
down: [i]dpov[/i]
up: [i]upov[/i]
left: [i]lpov[/i]
right: [i]rpov[/i]

For the left analog stick you'll need to use bind instead of bindCmd:
globalActionMap.bind(joystick, "xaxis", "playerMove");  //left stick x-axis
globalActionMap.bind(joystick, "yaxis", "playerMove");  //left stick y-axis

function playerMove(%val) {  //%val is a float ranging from -1 to 1, corresponding to the position of the stick on the axis

  [i]movement code[/i]

}

If you want to use the right stick at some point, you'll be using rxaxis and ryaxis.
Also, zaxis would be used for the analog triggers.
#8
10/28/2006 (7:14 pm)
That was the trick.....Thank you much Teck :)
#9
12/06/2006 (7:10 pm)
Sorry that I wasn't able to reply to this, something came up and I haven't been on these forums for a while.