Welcome to MSDN Blogs Sign in | Join | Help

Massaging thumbsticks

Gamepad thumbsticks return floating point values ranging from -1 to 1. It can be tempting to hook these inputs directly up to your physics, writing code like:

    turn += gamepad.ThumbSticks.Left.X * turnRate;

But wait! Are you sure this is really what you want? Good analog control has a huge impact on the feel of a game, and massaging your input values can do wonders to make things feel more controllable and responsive.

I like to apply a power curve to my analog inputs:

    const float power = 3;

    turn += PowerCurve(gamepad.ThumbSticks.Left.X) * turnRate;

    float PowerCurve(float value)
    {
        return (float)Math.Pow(Math.Abs(value), power) * Math.Sign(value);
    }

This response curve makes small input values even smaller, allowing for more precise control, but still preserves the full range when you move the stick to an extreme position:

In effect, it makes analog inputs feel even more analog than they normally would. Higher power values make the curve more pronounced, while smaller ones make it more subtle: somewhere around 2 or 3 is usually good.

Setting the power to 1 turns the curve into a no-op, while fractional values reverse the effect, making the controls feel more discrete and digital:

Published Friday, March 30, 2007 9:50 AM by ShawnHargreaves

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Friday, March 30, 2007 4:17 PM by Ultrahead

# re: Massaging thumbsticks

Weird title, great advice ...

Tuesday, April 03, 2007 1:40 AM by Mykres Space

# XNA Weekly Roundup 27-03-07 to 01-04-07

Here we go again with another weekly update; sorry it is a bit late. But it as been another quiet week

Saturday, May 10, 2008 2:01 AM by Virtual Realm

# XNA Weekly Roundup 27-03-07 to 01-04-07

Here we go again with another weekly update; sorry it is a bit late. But it as been another quiet week in the world of XNA, but this week we have seen a few new Bloggers come onto the scene (Lets hope they keep the content flowing). We have also seen

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker