Game Development Community

360 controller not working right

by mark romero · in Torque Game Engine · 11/25/2009 (1:25 pm) · 2 replies

i've recently discovered that i can use a 360 controller in torque, so i've attempted to add it. there are several problems with the joysticks though, when i press up he goes back and when i press down he goes forward. it did the same even when i switched the two. he also keeps moving until i press the opposite direction, and never stops turning down/right unless i turn him manually. here's my code:
function LAnaglogX( %value )
{

if(%value> -0.127062 && %value< 0.127062)
{
%value=0;
}
else if (%val > 0.0)
{
moveright(1);
moveright(0);
}


else if (%val < 0.0)
{
moveleft(1);
moveleft(0);
}
}
function LAnaglogY( %value )
{
if(%value> -0.127062 && %value< 0.127062)
{
%value=0;
}
else if ( %value > 0.01 )
{
movebackward(1);
movebackward(0);
}
else if ( %value < 0.01 )
{
moveforward(1);
moveforward(0);
}
}
function RAnaglogX( %value )
{
if(%value<0.1&&%value>-0.1)
{
%value=0;
}
else()
{
yaw();
}
}
function RAnaglogY( %value )
{
if(%value<0.1&&%value>-0.1)
{
%value=0;
}
else
{
pitch();
}
}

any suggestions or fixes?

#1
11/25/2009 (2:35 pm)
i've managed to fix it a little while after posting, here is the new code:

function yaw2(%val)
{
$mvYaw += getMouseAdjustAmount2(%val);
}

function getMouseAdjustAmount2(%val)
{
// based on a default camera fov of 90'
return(%val * ($cameraFov / 90) * 0.03);
}
function pitch2(%val)
{
$mvPitch += getMouseAdjustAmount2(%val);
}
// a break here, other code is in between
$enableDirectInput = "1";
activateDirectInput();
enableJoystick();

//BUTTONS
moveMap.bindCmd(joystick, "button0", "jump2();", "");
moveMap.bindCmd(joystick, "button1", "teleport();", "");
moveMap.bindCmd(joystick, "button2", "Dance();", "");
moveMap.bindCmd(joystick, "button3", "toggleFirstPerson();", "");
moveMap.bindCmd(joystick, "button4", "findBombs();", "");
moveMap.bindCmd(joystick, "button5", "echo(\"Pressed RB\");", "");
moveMap.bindCmd(joystick, "button6", "escapeFromGame();","");
moveMap.bindCmd(joystick, "button7", "echo(\"Pressed START\");", "");
moveMap.bindCmd(joystick, "button8", "echo(\"Pressed L-ANALOG\");", "");
moveMap.bindCmd(joystick, "button9", "echo(\"Pressed R-ANALOG\");", "");

// ANALOG
moveMap.bind(joystick, xaxis, "LAnaglogX");
moveMap.bind(joystick, yaxis, "LAnaglogY");
moveMap.bind(joystick, rxaxis, "RAnaglogX");
moveMap.bind(joystick, ryaxis, "RAnaglogY");
moveMap.bind(joystick, zaxis, "LTRTAnaglog");

// D-PAD
// Press are release
moveMap.bindCmd( joystick, upov, "useSmg();", "" );
moveMap.bindCmd( joystick, dpov, "useRocket();", "" );
moveMap.bindCmd( joystick, lpov, "useCrossbow();", "" );
moveMap.bindCmd( joystick, rpov, "useShotgun();", "" );
// Press before releasing of previous pov
moveMap.bindCmd( joystick, upov2, "useBlaster();", "" );
moveMap.bindCmd( joystick, dpov2, "echo(\"Pressed DPOV2\");", "" );
moveMap.bindCmd( joystick, lpov2, "echo(\"Pressed LPOV2\");", "" );
moveMap.bindCmd( joystick, rpov2, "echo(\"Pressed RPOV2\");", "" );

function LAnaglogX( %value )
{
if(%value> -0.127062 && %value< 0.127062)
{
%value=0;
moveright(%value);
moveleft(%value);
}
else if (%value > 0.01)
{
moveright(1);
}
else if (%value < -0.01)
{
moveleft(1);
}
}
function LAnaglogY( %value )
{
if(%value> -0.127062 && %value< 0.127062)
{
%value=0;
moveforward(%value);
moveBackward(%value);
}
else if ( %value > 0.01 )
{
movebackward(1);
}
else if ( %value < 0.01 )
{
moveforward(1);
}
}
function RAnaglogX( %value )
{
if(%value<0.1&&%value>-0.1)
{
%value=0;
yaw2(%value);
}
else
{
yaw2(%value);
}
}
function RAnaglogY( %value )
{
if(%value<0.1&&%value>-0.1)
{
%value=0;
pitch2(%value);
}
else
{
pitch2(%value);
}
}
function LTRTAnaglog( %value )
{
if ( %value != 0 )
mouseTrigger();
mouseTrigger();
}
jump2 is a basic funtion that calls jump twice so the character only jumps once, and mousetrigger is called twice to start and stop firing. also, the yaw2 and pitch 2 are different only because they are more sensitive. this code should be able to be added into any game and work properly.
#2
11/25/2009 (10:16 pm)
might give this code a look, skip to the second page:

www.garagegames.com/community/forums/viewthread/103339/