Xbox 360 Controller in TGEA
by Travis Vroman · in Torque Game Engine Advanced · 01/28/2009 (1:24 pm) · 9 replies
Okay, so I have been trying to get the Xbox 360 controller working in TGEA 1.7.1.
So far, I have found this wiki page:
http://tdn.garagegames.com/wiki/Torque/EngineMods/Xbox360ControllerSupport
This, however, was for an old version of TGE and is probably not up to date. I did, however, compare the code in the provided source files to the ones in TGEA, and it would seem that most of the code is already there, albeit somewhat different in some locations.
I also implemented and modified the script files to only deal with one controller to try and simplify things.
The controller powers on when TGEA starts and is detected and named "joystick0" (the code names it this weather it's a joystick or a game pad according to the code). I adjusted the scripts to refer to this device correctly instead of "xinpux0" etc, as the original scripts did. I also added echo statements for each button press so I could see in the console what button I pushed and that it was recognized.
The problem is that the controller is not recognized in the gui as connected.
Oddly enough, though the gui states the controller is not connected, the dpad echo statements show properly in the console when I press the respective buttons. Nothing else will work though, not the joysticks or any other buttons.
I've searched through the forums and resources now for a while and have found nothing to point me in the right direction that I could access (most of it seems to be tgb stuff, which does me no good if I cant see it.)
Any help with this would be much appreciated.
Cheers,
-Travis
So far, I have found this wiki page:
http://tdn.garagegames.com/wiki/Torque/EngineMods/Xbox360ControllerSupport
This, however, was for an old version of TGE and is probably not up to date. I did, however, compare the code in the provided source files to the ones in TGEA, and it would seem that most of the code is already there, albeit somewhat different in some locations.
I also implemented and modified the script files to only deal with one controller to try and simplify things.
The controller powers on when TGEA starts and is detected and named "joystick0" (the code names it this weather it's a joystick or a game pad according to the code). I adjusted the scripts to refer to this device correctly instead of "xinpux0" etc, as the original scripts did. I also added echo statements for each button press so I could see in the console what button I pushed and that it was recognized.
The problem is that the controller is not recognized in the gui as connected.
Oddly enough, though the gui states the controller is not connected, the dpad echo statements show properly in the console when I press the respective buttons. Nothing else will work though, not the joysticks or any other buttons.
I've searched through the forums and resources now for a while and have found nothing to point me in the right direction that I could access (most of it seems to be tgb stuff, which does me no good if I cant see it.)
Any help with this would be much appreciated.
Cheers,
-Travis
#2
Thanks again,
-Travis
01/28/2009 (6:47 pm)
This is awesome, I can't wait to try it out. I was also going to look into having the character walk anyways, so perhaps this will get me started in that regard as well. At the top though, you mentioned to ignore the $, but which one are you referencing as the one that I can ignore?Thanks again,
-Travis
#3
01/28/2009 (8:45 pm)
I'm sorry - I meant ignore the $mvWalk - That's used internally to modify the speed and animation of the moving character. It's part of the Torque Motion Pack.
#4
Cheers,
-Travis
01/29/2009 (4:24 am)
Ah, okay. I guess I'll have to try and code the walking function in myself. Shouldn't be too big of a deal. However, I would like you to know that I have the controller working perfectly now, even including the triggers! I was able to make the left trigger zoom and the right trigger fire the weapon using a positive/negative value of the z-axis, which is what the triggers are it seems. Anyways, I really appreciate your help, Jaimi. :)Cheers,
-Travis
#5
Have you guys gotten this to work in the Stronghold mission? I'm having some troubles. Only the 'A' and 'X' button work on my xbox 360 controller. In the T3D demo, I got it working without any trouble.
Thanks,
Kerry
01/29/2009 (6:11 pm)
Hi,Have you guys gotten this to work in the Stronghold mission? I'm having some troubles. Only the 'A' and 'X' button work on my xbox 360 controller. In the T3D demo, I got it working without any trouble.
Thanks,
Kerry
#6
$enableDirectInput = "1";
activateDirectInput();
enableJoystick();
01/29/2009 (6:15 pm)
Did you add this in PlayGui::OnWake?$enableDirectInput = "1";
activateDirectInput();
enableJoystick();
#7
For example, A is button 1 in the control panel interface, but torque recognizes it as button0. B is 2 in CP, in TGEA it is button1. Etc, etc...
Since you are able to use the controller somewhat in game play, it sounds like the buttons aren't correctly mapped.
The two triggers on the xbox controllers are the z axis, which returns a negative value for the left trigger and a positive value for the right trigger. These can be used to bind each trigger to a command.
Hope this helps,
-Travis
01/30/2009 (11:25 am)
I have this working perfectly in Stronghold. The way I found out what buttons were what was I went into the game controllers in the control panel and opened up the settings dialog, which gave me an interface showing the buttons (numbered) and the axis feedback for the 2 joysticks and the triggers. For the buttons, they show up as 1-10 on the interface as you press them. Simply take that number and subtract 1 from it, and you will have the button number that torque recognizes.For example, A is button 1 in the control panel interface, but torque recognizes it as button0. B is 2 in CP, in TGEA it is button1. Etc, etc...
Since you are able to use the controller somewhat in game play, it sounds like the buttons aren't correctly mapped.
The two triggers on the xbox controllers are the z axis, which returns a negative value for the left trigger and a positive value for the right trigger. These can be used to bind each trigger to a command.
Hope this helps,
-Travis
#8
@ Travis: That's a good tip for setting up the correct buttons. Does the rest of your gamepad code look like Jaimi's?
Thanks for the help! I'll try this out tomorrow.
01/30/2009 (9:07 pm)
@ Jaimi: I did enter that code into PlayGui::OnWake. I think I will also copy the exact code you posted instead of using the defaultbind.cs from TGEA 1.8.@ Travis: That's a good tip for setting up the correct buttons. Does the rest of your gamepad code look like Jaimi's?
Thanks for the help! I'll try this out tomorrow.
#9
Also, I forgot to mention I'm using 'Stronghold' from TGEA 1.8 so maybe that's the problem
Update: Rookie mistake! I forgot to delete the prefs.cs...Doh! Now it works. Thanks again.
01/31/2009 (2:30 pm)
Well, unfortunately, still no luck. I'm probably missing something else in the defaultbind.cs...Also, I forgot to mention I'm using 'Stronghold' from TGEA 1.8 so maybe that's the problem
Update: Rookie mistake! I forgot to delete the prefs.cs...Doh! Now it works. Thanks again.
Associate Jaimi McEntire
King of Flapjacks
This was all I did to get xbox 360 controller support.
In default.bind.cs, I added the following code. Note that my players can "walk" instead of run when the stick is not pushed all the way, this is handled elsewhere, you can ignore the $
function gamePadMoveX( %val ) { if ($mvWalk) { if (%val > 0.6 || %val < -0.6) { $mvWalk = 0; $mvXAxis_L = %val * 0.8; } else $mvXAxis_L = %val * 1.6; } else { $mvXAxis_L = %val * 0.8; } } function gamePadMoveY( %val ) { if (%val > 0.6 || %val < -0.6) { $mvYAxis_L = -(%val * 0.8); $mvWalk = 0; } else { $mvYAxis_L = -%val; if ($mvXAxis_L > 0.6 || $mvXAxis_L < -0.6) { // Strafing, need to "not walk"; $mvWalk = 0; } else { $mvWalk = 1; } } } function gamePadYaw( %val ) { $mvYawRightSpeed = -0.1 * %val; } function gamePadPitch( %val ) { $mvPitchUpSpeed = 0.1 * %val; // Inverted! } $enableDirectInput = "1"; activateDirectInput(); //Buttons moveMap.bind( joystick, button0, jump ); moveMap.bind( joystick, button1, altTrigger ); moveMap.bind( joystick, button2, toggleFirstPerson ); moveMap.bind( joystick, button6, toggleCamera); //Right Stick moveMap.bind( joystick, rxaxis,"D", "-0.23 0.23", gamePadMoveX ); moveMap.bind( joystick, ryaxis,"D", "-0.23 0.23", gamePadPitch ); //Left Stick moveMap.bind( joystick, xaxis, "D", "-0.23 0.23", gamePadYaw ); moveMap.bind( joystick, yaxis, "D", "-0.23 0.23", gamePadMoveY ); // D-PAD // Press are release moveMap.bind( joystick, upov, "moveforward" ); moveMap.bind( joystick, dpov, "movebackward" ); moveMap.bind( joystick, lpov, "moveleft" ); moveMap.bind( joystick, rpov, "moveright" ); // Press before releasing of previous pov moveMap.bind( joystick, upov2, "moveforward" ); moveMap.bind( joystick, dpov2, "movebackward" ); moveMap.bind( joystick, lpov2, "moveleft" ); moveMap.bind( joystick, rpov2, "moveright" );in PlayGui.cs, PlayGui::OnWake I added the following code to regrab the control in case the window wasn't focused at loadup.
$enableDirectInput = "1";
activateDirectInput();
enableJoystick();
This works correctly with GuiGameListMenuCtrl (like at the start of T3D) as well as using it for player control. Originally, the Pitch/MoveY were inverted, but I decided I like it better this way.