Game Development Community

Fluid joystick trick

by Luis Anton · in Hardware Issues · 06/14/2004 (1:09 am) · 6 replies

Hi!

If you want to use a joystick with Torque, there are some steps you must follow:

1) set $pref::Input:JoystickEnabled = "1";

2) create some functions in fps/client/scripts/default.bind.cs to control it:

function joystickYaw(%val)
{
$mvYaw = getMouseAdjustAmount(%val);
}

3) bind joystick axes to those functions, or existing functions, in fps/client/config.cs:

moveMap.bind(joystick0, "xaxis", joystickYaw);
moveMap.bind(joystick0, "yaxis", moveforward);

And then just play. But you will soon realice that, while the forward/backward movement is smooth, yawing doesn't work properly. I remember I had to do something in gameConnectionMoves.cc: bool GameConnection::getNextMove(Move &curMove). The joystick doesn't work properly because of these lines:
MoveManager::mPitch = 0;
   MoveManager::mYaw = 0;
   MoveManager::mRoll = 0;

If you comment them, then your joystick will work perfectly... but the mouse wont :( I need to know if movement comes from a joystick or the mouse, so I can change those lines properly. Something like:
if (usingMouse())
{
   MoveManager::mPitch = 0;
   MoveManager::mYaw = 0;
   MoveManager::mRoll = 0;
}

Someone told me a few month ago the solution on IRC, but I don't remember it. Which was the solution? I know it was quite simple, but I just cannot remember it. I should begin writing down those things... please help!

#1
06/14/2004 (3:31 am)
Well, I found something at the end of this link:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3780

I'll try it when I arrive home :)
#2
06/15/2004 (11:37 am)
Interesting. I did joysticks for aircraft, and instead created a separate bunch of functions for controlling them using mouse and keyboard (and of course joystick).

Basically had the mouse movement add onto $mvYawLeftSpeed, $mvPitchUpSpeed, $mvRollLeftSpeed

With that technique you have to cap those values at -0.5*PI and 0.5*PI, but it feels pretty good.
#3
10/24/2004 (10:17 pm)
Luis, did the yaw2/pitch2 trick work out for you? I've applied the code found in the resource you mention but my yaw and pitch still don't work properly. Did you find an answer to this problem?
#4
10/26/2004 (10:03 am)
Here's my final code in client/scripts/default.bind.cs:

$pref::Input::Sensitivity = "0.02";

function getJoystickAdjustAmount(%val)
{
   if( %val > - 0.5 && %val < 0.5 )
      return 0;

   return(%val * ($cameraFov / 90) * $pref::Input::Sensitivity);
}


function moveforward2(%val)
{
   if( %val > - 0.7 && %val < 0.7 )
   {
      $mvForwardAction = 0;
      return;
   }
      
   $mvForwardAction = -%val*$movementSpeed;
}

function yaw2(%val)
{
   $pref::usandoJoystick = true;
      
   $mvYaw = getJoystickAdjustAmount(%val);
}

function pitch2(%val)
{
   $pref::usandoJoystick = true;
   
   if($pref::Input::InvertMouse)
   {
      $mvPitch = getJoystickAdjustAmount(%val);
   }
   else
   {
      $mvPitch = getJoystickAdjustAmount(%val);
   }
}

but I can find no changes in code, so you may not need them. Please try that and tell me if it is enough. Of course, in movemap you have to use those functions for the joytick

moveMap.bind(joystick0, "xaxis", yaw2);
moveMap.bind(joystick0, "yaxis", moveforward2);

good luck!
#5
03/31/2007 (8:03 pm)
Ok digging up this old post hehe. Currently trying to get a Xbox 360 controller to work on TSE. This code and some others helped alot in trying to get Yaw/Pitch to work.

Problem I'm having still is that yaw/pitch is not smooth in motion like when I move around with Forward/Backword/Left/Right. Also when I release the stick it yaw/pitch again as it returns to deadzone. I know it must be something super simple i'm missing if someone can show me or point me in the correct direction to fix this issue. I'm still a newbie programmer but catching on.

Thanks for your time.
#6
12/16/2007 (10:47 pm)
Does anybody by any chance have any code to offer on the "if (usingMouse())" concept?

I swear to the world that the first thing I'm going to do when I finish this game is take a C++ class. I'm tired of being a helpless little baby when it comes to the source!

On the other hand, I'm surprised more people haven't run into the joystick un-goodness.