Getting DPad Input from Thumbsticks in XNA – The Right Way

If you want to simulate 4-way DPad movement with the left or right analog thumbstick in XNA, my advice is to never use Buttons.LeftThumbStickUp, etc. This is because the default behavior doesn’t take into account the dead zone for the stick, which varies from controller to controller.  (The dead zone is the location near the center of the stick position, where it won’t send any movement value to the Xbox.)

You might test on a controller with a large dead zone and have no problem, then someone else will play your game with a very small dead zone, and they will find the control “sticking” in that direction.  I’ve had some controllers where the dead zone was so precise, I could have my thumb off the joystick and it would still be transmitting a tiny movement value.

I suggest adding a large dead zone, to make sure you only get simulated DPad input for large, deliberate movements of the analog stick.  Here’s some code that works for me, adjust as necessary to fit your control scheme:

static Buttons GetThumbstickDirection(PlayerIndex player, bool leftStick)
{
    float thumbstickTolerance = 0.35f;

    GamePadState gs = GamePad.GetState(player);
    Vector2 direction = (leftStick) ? 
        gs.ThumbSticks.Left : gs.ThumbSticks.Right;

    float absX = Math.Abs(direction.X);
    float absY = Math.Abs(direction.Y);

    if (absX > absY && absX > thumbstickTolerance)
    {
        return (direction.X > 0) ? Buttons.DPadRight : Buttons.DPadLeft;
    }
    else if (absX < absY && absY > thumbstickTolerance)
    {
        return (direction.Y > 0) ? Buttons.DPadUp : Buttons.DPadDown;
    }
    return (Buttons)0;
}

Escape Goat Featured in “Best of 2011” Lists

ArmlessOctopus – The Top Xbox Live Indie Games of 2011

“It’s the kind of game where the answer is always right in front of your face, even if it takes a few frustrating failures to find it.”

HiddenAudioLog – Xbox Live Indie Game of the Year 2011:

“Escape Goat is the definition of a complete package, and is borderline flawless at what it sets out to achieve. That’s why Escape Goat is not only Hidden Audio Log’s Xbox Live Indie Game of the Year of 2011, but probably the best Xbox Live Indie Game ever.”

Destructoid – Manasteel’s A Better List than Microsoft’s “Best of 2011: Indie Games”:

“Escape Goat is from the same creative developer that gave us the Soul Caster titles. The game offers the players a lot as a puzzle based platformer, especially once you create your own puzzle rooms. As a Goat, you have to escape your persecution with the help of a rat, a magical hat, and a lot of planning. It’s shocking what one single developer can create and this is indeed a good game. “

Gamecritics.com – Brad Gallaway’s Top 10 of 2011:

“What do you get when you combine a barnyard animal, a wall-climbing mouse and a magic hat? A damned good puzzle game.

IndieGamerChick – Top 10 of All Time (#2 spot):

“It’s clever, punchy, and controls absolutely flawlessly.  It hits all the right notes for what a puzzle-platformer should be.”

Gamezone – Best Xbox Live Indie Games of 2011

“It’s an innocent premise aided by some fantastically clever puzzle-solving gameplay.”

Gamasutra – Best of 2011 – Top 5 Overlooked Games (Honorable Mention)

NeoGAF users seem to like it as well.