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?
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?
About the author
#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)
}
Chaim Krause
Chaim Gang