Game Development Community

dev|Pro Game Development Curriculum

Xbox 360 Controller Setup

by Britt Scott · 10/19/2012 (8:31 pm) · 13 comments

Tested using T3D Open Source(10/15/12) and Windows 7

1. Plug in you xbox 360 controller

1a. The wired Xbox 360 controller is interchangable with the pc and xbox. If you plug in your xbox controller and check for windows updates, it should find the drivers for you.

1b. I also believe a wireless Xbox 360 controller and the play and recharge cable will work too.

2. Update controller drivers(Skip if step was already completed in 1a)

3. Open My Projects/NameofProjectHERE/game/scripts/client/default.bind.cs with a script editor

4. Find:
moveMap.bind(keyboard, q, nextWeapon);
moveMap.bind(keyboard, ctrl q, prevWeapon);
moveMap.bind(mouse, zaxis, mouseWheelWeaponCycle);

5. Just below it, add:
moveMap.bind(gamepad, btn_l, prevWeapon);			//Shoulder_LT	Edited
moveMap.bind(gamepad, btn_r, nextWeapon);			//Shoulder_RT	Edited

6. Save and Startup T3D
7. The controller shoulder buttons should now cycle through weapons
8. For more examples, see full script. NOTE: Controls aren't set in stone, feel free to change them!

i226.photobucket.com/albums/dd48/stacalkas/Xbox360MapT3D-1.jpg
The full script that the table below references.
|	Script Name	|	Physical Button			|	Current Function

// Controller connect / disconnect:
|	connect		|	Xbox Button				|	Display echo in console 
   
// L and R Thumbsticks:
|	thumblx		|	Left Thumb Left-Right	|	Move Left-Right
|	thumbly		|	Left Thumb Up-Down		|	Move Forward-Backwards
|	thumbrx		|	Right Thumb Left-Right	|	Look Left-Right
|	thumbry		|	Right Thumb Up-Down		|	Look Up-Down

// L and R Triggers:
|	triggerl	|	Left Trigger			|	Alt-Fire
|	triggerr	|	Right Trigger			|	Fire

 // DPAD Buttons:
|	dpadu		|	D-Pad Up				|	Open Console
|	dpadd		|	D-Pad Down				|	Toggle Normals
|	dpadl		|	D-Pad Left				|	Toggle Lighting
|	dpadr		|	D-Pad Right				|	metrics(fps)

// START and BACK Buttons:
|	btn_start	|	Start					|	Toggle free-camera
|	btn_back	|	Back					|	Disconnect

// L and R Thumbstick Buttons:
|	btn_lt		|	Left Thumb Press		|	Sprint
|	btn_rt		|	Right Thumb Press		|	Zoom

// L and R Shoulder Buttons:
|	btn_l		|	Left Shoulder			|	Previous Weapon
|	btn_r		|	Right Shoulder			|	Next Weapon

// Primary buttons:
|	btn_a		|	A						|	Jump
|	btn_b		|	B						|	Toggle crouch
|	btn_x		|	X						|	Reload weapon
|	btn_y		|	Y						|	Toggle 1st/3rd view

Update - Gamepad Vehicles
If the player mounts a vehicle while using a gamepad, the vehicle will start driving on its own.

To fix this, find:

in client/client.cs
function clientCmdtoggleVehicleMap(%toggle)  
{  
   if(%toggle)  
   {  
      moveMap.pop();  
      vehicleMap.push();  
   }  
   else  
   {  
      vehicleMap.pop();  
      moveMap.push();  
   }  
}

and add 2 lines to it:

function clientCmdtoggleVehicleMap(%toggle)  
{  
   if(%toggle)  
   {  
    $mvForwardAction = 0;//Gamepad vehicle stop     BrittEdit  
    $mvBackwardAction = 0;//Gamepad vehicle stop    BrittEdit  
      moveMap.pop();  
      vehicleMap.push();  
   }  
   else  
   {  
      vehicleMap.pop();  
      moveMap.push();  
   }  
}

This will keep the vehicle at rest until the game receives input from the user.

Update 11/15/12 - Gamepad Rumble
Can't believe I forgot about this! *smacks head*

We will begin with starting the rumble

in client/default.bind.cs find:
if(%val > 0.1 && !$gamepadFireTriggered)
   {
      $gamepadFireTriggered = true;
      $mvTriggerCount0++;
   }

just below $mvTriggerCount0++; and inside the if statement, add:
rumble(gamepad, 0.25, 0.25);//deviceName, Left Motor(low-frequency),Right Motor(high-frequency)

Then we will stop the rumble

in client/default.bind.cs find:
else if(%val <= 0.1 && $gamepadFireTriggered)
   {
      $gamepadFireTriggered = false;
      $mvTriggerCount0++;
   }

just below $mvTriggerCount0++; and inside the else if statement, add:
rumble(gamepad, 0, 0);

I'm no programmer, but I try.

Questions and comment are welcome!

About the author

Attended Brown College in Mendota Heights, MN for Game Design and Development. Projects include the Mech Starter Kit and the Battle Frog. Currently working toward a game design career.


#1
10/23/2012 (12:44 pm)
Britt,
Is this Xbox controller the PC version or the same controller that comes with the Xbox 360?
Also, when you say update drivers then what drivers do you mean:
The drivers for the PC version of this controller?
The drivers for the Xbox version of the controller?

I wasn't even aware the xbox controllers needed updating, do they ?

Please clarify.
#2
10/23/2012 (2:00 pm)
@Scott, I haven't got a Xbox360 or controller but as I understand it you can get a cable that plugs your Xbox360 controller directly into your PC, the pc needs the drivers installing and updating to use it with Torque3D or for that matter any PC game.

I have a Xbox360 Kinect plugged into my PC in the same way :-)
#3
10/23/2012 (10:41 pm)
The wired Xbox 360 controller is interchangable with the pc and xbox. If you plug in your xbox controller and check for windows updates, it should find the drivers for you.

I also believe a wireless Xbox 360 controller and the "play and recharge" cable will work too.

Let me know if that isn't clear enough. I'll then update the resource to help prevent confusion.
#4
10/24/2012 (12:25 am)
This works as written.
My ignorance is based on shopping for a controller and found there are different marketing techniques for them.
Some controllers are marked as Xbox and PC compatible while others simply read XBox compatible.
My XBox controller does get detected when I plug it into my PC and drivers are installed for it automatically in Windows Vista 64bit.
Before I tested the code I went ahead and installed the controller drivers from Microsoft.

Thank you for this recent Gamepad resource. I've been wanting to test this sort of thing.
#5
10/24/2012 (9:41 am)
Quick Note: I'm having problems moving from the player to vehicle controls. If the player runs up to the Cheetah using the gamepad, the vehicle will continue moving forward even if no buttons are used. Using the right trigger will allow you control the vehicle.
#6
10/24/2012 (1:02 pm)
Playing with the default.binds.cs file a little bit i made some changes to your script that seems to sometimes fix the runaway Cheetah.
I think the issue has to do with the starting %val received from the gamepad.
Same thing happens when exiting the Cheetah for the Player.

The issue stops if I move the thumbr a bit and I gain full control as usual.

Right Thumb = forward / reverse / turning
Right Thumb button press = exit the vehicle
Button A = Brake


vehicleMap.bind( keyboard, w, moveforward );
vehicleMap.bind( gamepad, thumbry, moveforward );      // Edit Scott.W
vehicleMap.bind( keyboard, s, movebackward );
vehicleMap.bind( keyboard, up, moveforward );
vehicleMap.bind( keyboard, down, movebackward );
vehicleMap.bind( gamepad, thumbrx, gamepadYaw );      // Edit Scott.W
vehicleMap.bind( mouse, xaxis, yaw );
vehicleMap.bind( mouse, yaxis, pitch );
vehicleMap.bind( mouse, button0, mouseFire );
vehicleMap.bind( mouse, button1, altTrigger );
vehicleMap.bindCmd(gamepad, "btn_rt","getout();",""); // Edit Scott.W
vehicleMap.bindCmd(keyboard, "ctrl f","getout();","");
vehicleMap.bind(gamepad, btn_a, brake);               // Edit Scott.W
vehicleMap.bind(keyboard, space, brake);
vehicleMap.bindCmd(keyboard, "l", "brakeLights();", "");
vehicleMap.bindCmd(keyboard, "escape", "", "handleEscape();");
vehicleMap.bind(keyboard, h, showControlsHelp);
vehicleMap.bind( keyboard, v, toggleFreeLook ); // v for vanity
//vehicleMap.bind(keyboard, tab, toggleFirstPerson );
vehicleMap.bind(keyboard, "alt c", toggleCamera);

Again, thank you for the resource, Britt.
#7
10/24/2012 (6:29 pm)
This is a great resource! Thanks
#8
10/25/2012 (11:43 am)
A long awaited resource... Every forum question should point to this resource... Nice Britt
#9
10/25/2012 (12:01 pm)
@Scott, see if this helps:

In client/client.cs, find:
function clientCmdtoggleVehicleMap(%toggle)
{
   if(%toggle)
   {
      moveMap.pop();
      vehicleMap.push();
   }
   else
   {
      vehicleMap.pop();
      moveMap.push();
   }
}

Add the following:
function clientCmdtoggleVehicleMap(%toggle)
{
   if(%toggle)
   {
	$mvForwardAction = 0;//Gamepad vehicle stop		BrittEdit
	$mvBackwardAction = 0;//Gamepad vehicle stop	BrittEdit
      moveMap.pop();
      vehicleMap.push();
   }
   else
   {
      vehicleMap.pop();
      moveMap.push();
   }
}

Most people may only need the forward set to zero. I added the backwards just in case the player walked backwards into a vehicle.
#10
10/25/2012 (10:47 pm)
Added your code addition to client.cs and the problem is fixed.
Can't say thank you enough times Britt.
#11
10/26/2012 (2:30 pm)
Updated
#12
11/15/2012 (10:41 am)
Update bump
#13
11/15/2012 (7:30 pm)
[Update]
Rumble is very slight when firing bullets.