Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Right now it feels like the deadzoning is being done per axis of the joypad, which will result in it feeling like its moving in a single axis when I am trying to move at a diagonal.

Not that this is pefect code, but here's what I'm doing on my current project. (V2 is a float[2], V2I is a int[2]). The relevant part is that it checks if the magnitude of the pair of axes exceeds the deadzone threshold, zeros it if it does and subtracts that much magnitude out otherwise.

Code provided "as-is"

V2I deadThumb(int ix, int iy)
{
   // was XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, but my older joypads were skidding with that.
   const int INPUT_DEADZONE = 11000;
   const int kMaxStickVal    = 32767; // positive or negative, post-deadzoning


   V2 thumb(ix + 0.5f, iy + 0.5f);


   //determine how far the controller is pushed
   float magnitude = thumb.length();
   const float kMaxMagnitude = kMaxStickVal + 0.49f;
   const float kNoiseMagnitude = INPUT_DEADZONE;
   if (magnitude > kMaxMagnitude)
   {
      thumb *= kMaxMagnitude / magnitude;
   }
   else if (magnitude < kNoiseMagnitude)
   {
      thumb = V2(0, 0);
   }
   else
   {
      // remove deadzone and renormalize
      float scalar = (magnitude - kNoiseMagnitude) / (kMaxMagnitude - kNoiseMagnitude);
      thumb *= kMaxMagnitude * scalar / magnitude;
   }


   V2I ret;
   ret.x = Math::round(thumb.x);
   ret.y = Math::round(thumb.y);


   return ret;
}