Game Development Community

Binding functions to joystick events

by Koen Van Baelen · in Torque Game Builder · 11/20/2007 (8:16 am) · 2 replies

Here's a sample from my code. This is in the onAdd() function:

moveMap.bind(joystick0,"xaxis","$Gun.xaxisPress();");

and here's the xaxisPress function:

function gunEngine::xaxisPress(%this, %val)
{
if (%val < -0.1) %this.setConstantForceX(-25);
if (%val > 0.1) %this.setConstantForceX(25);
if (%val == 0) %this.setConstantForceX(0);
}

When I run the game and try to move with the gamepad, I get this error in the console window:

$Gun.xaxisPress(); : unknown command

What am I doing wrong?

#1
11/20/2007 (3:42 pm)
Take a look at the examples. You have mixed up a few things. First of all you have mixed the parameters of bind() and bindCMD(). You also need to change your function as it can only take one paramater - %val. You also need to remove it from the gunEngine namespace as there will be no associated object.
#2
12/18/2007 (12:02 am)
I would try:
moveMap.bind(joystick0, "xaxis", "joystickInputX();");

$joystickDeadZone = 0.1;
$joystickSensitivity = 30;

function joystickInputX(%val)
{
   if (mAbs(%val) > $joystickDeadZone)
      $player.setConstantForceX(%val * $joystickSensitivity) // analog control
   else
      $player.setConstantForceX(0)
}