Stop Left-Over Gamepad Input

Scripting questions, discussions, etc
2 posts Page 1 of 1
Steve_Yorkshire
Posts: 238
Joined: Tue Feb 03, 2015 10:30 pm
 
  by Steve_Yorkshire » Mon Apr 16, 2018 10:31 pm
Okeedokee, here's a funny little thing I found. If you exit a level whilst still having the gamepad stick in movement, the input locks and is remembered when you start a new mission the movement input restarts.

How to test in default Torque:
1) Have a gamepad (durrrr)
2) Load a mission and start moving.
3) Keep pressure on the thumbstick and exit using the Back button on gamepad, or Esc/select quit/yes with mouse (keep that thumbstick in move position)
4) At Main Menu release gamepad
5) Start new mission
6) See player start moving from leftover input

Solution:

in scripts/client/default.bind.cs, add this new function (anywhere is fine)
//to stop movement being left over, after death or end of mission
function gamePadEnd()
{
$mvYawLeftSpeed = 0;
$mvYawRightSpeed = 0;
$mvPitchUpSpeed = 0;
$mvPitchDownSpeed = 0;

$mvRightAction = 0;
$mvLeftAction = 0;
$mvForwardAction = 0;
$mvBackwardAction = 0;
}


In scripts/server/gameCore.cs, add this at the bottom of onMissionEnded
function GameCore::onMissionEnded(%game)
{
//echo (%game @"\c4 -> "@ %game.class @" -> GameCore::onMissionEnded");

// Called by endMission(), right before the mission is destroyed

// Normally the game should be ended first before the next
// mission is loaded, this is here in case loadMission has been
// called directly. The mission will be ended if the server
// is destroyed, so we only need to cleanup here.

physicsStopSimulation("server");
%game.endGame();

cancel($Game::Schedule);
$Game::Running = false;
$Game::Cycling = false;

//new from here
echo("c\4End any left over gamepad input");
gamePadEnd();//in default.bind.cs
}


You could probably also include a var to see if there is a gamepad connected or even cycle through gamepad inputs to see if any are still active, but this works fine.
JeffR
Steering Committee
Steering Committee
Posts: 808
Joined: Tue Feb 03, 2015 9:49 pm
 
by JeffR » Wed Apr 18, 2018 3:53 pm
Not a bad workaround :)

Still, feels like a bug in the input in general if we consider that the other keybinds don't have a similar sticking effect. Something we'll have to double-check on.

I know with the SDL stuff the core input handling is different(and we're still reviewing the gamepad side) so that may well be a non-issue when we get it all wrapped up, but this is definitely useful for people still rocking the windows platform layer.
2 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests