Game Development Community

Multiple gamepad support?

by WesTT · in Torque Game Builder · 06/16/2008 (5:50 am) · 1 replies

Hi everyone, hope your games are going well. I currently implementing gamepad support using my Xbox 360 controllers. I have player one setup ok, using both the analog and digital pad to move around, fire etc. All of this is setup via a behavior, using the KEYBIND dropdown list.

This works fine for player one, as it is bound automatically to "joystick0". I assume as there is a numerator at the end of that string that TGB supports multiple gamepads, would this be correct? Now my question becomes: how does one, using a behavior, bind keys to a second gamepad via the level editor? As it appears only a generic "joystick" field and a set of keybinds appear below that. I figured that perhaps I had to programmatically bind a certain controller to the second player at first, then apply that to the behaviors keybinds somehow, but couldn't find a way to do that.

I am currently using the following fields in the behavior
%template.addBehaviorField(xAxis, "The joystick's x-axis", keybind, "joystick0 xaxis");      %template.addBehaviorField(yAxis, "The joystick's y-axis", keybind, "joystick0 yaxis");

// Secondary directional controls
%template.addBehaviorField(up2, "The POV hat controls", keybind, "joystick0 upov");
%template.addBehaviorField(down2, "The POV hat controls", keybind, "joystick0 dpov");
%template.addBehaviorField(left2, "The POV hat controls", keybind, "joystick0 lpov");
%template.addBehaviorField(right2, "The POV hat controls", keybind, "joystick0 rpov");
%template.addBehaviorField(nextWeaponJoy, "The joystick next weapon button", keybind, "joystick0 button2");

And binding it as such:

moveMap.bindObj(getWord(%this.xAxis, 0), getWord(%this.xAxis, 1), "moveXAnalogJoy", %this);   
moveMap.bindObj(getWord(%this.yAxis, 0), getWord(%this.yAxis, 1), "moveYAnalogJoy", %this);   
   
moveMap.bindObj(getWord(%this.up2, 0), getWord(%this.up2, 1), "moveUp", %this);
moveMap.bindObj(getWord(%this.down2, 0), getWord(%this.down2, 1), "moveDown", %this);
moveMap.bindObj(getWord(%this.left2, 0), getWord(%this.left2, 1), "moveLeft", %this);
moveMap.bindObj(getWord(%this.right2, 0), getWord(%this.right2, 1), "moveRight", %this);

This might actually be quite simple and I'm missing something :) so please don't hesitate to let me know if you can see what I am doing wrong!

#1
06/16/2008 (7:42 pm)
Actually, this is a pretty basic solution that I thought about last night but was way too tired to implement (as evidenced by my original post, heh).

%controller = "joystick0" TAB "joystick1";
%template.addBehaviorField(controllerNum, "The controller to use", enum, "joytick0", %controller);
%template.addBehaviorField(xAxis, "The joystick's x-axis", keybind, "joystick0 xaxis");   
%template.addBehaviorField(yAxis, "The joystick's y-axis", keybind, "joystick0 yaxis");

And the bindings

moveMap.bindObj(%this.controllerNum, getWord(%this.xAxis, 1), "moveXAnalogJoy", %this);   
moveMap.bindObj(%this.controllerNum, getWord(%this.yAxis, 1), "moveYAnalogJoy", %this);

Just so no one else does anything silly like myself. :)