Skip to content

Instantly share code, notes, and snippets.

@drawcode
Created April 19, 2013 02:23
Show Gist options
  • Save drawcode/5417661 to your computer and use it in GitHub Desktop.
Save drawcode/5417661 to your computer and use it in GitHub Desktop.
// Scaled Radial Dead Zone
float deadzone = 0.25f;
Vector2 stickInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
float inputMagnitude = stickInput.magnitude;
if (inputMagnitude < deadzone)
{
stickInput = Vector2.zero;
}
else
{
// rescale the clipped input vector into the non-dead zone space
stickInput *= (inputMagnitude - deadzone) / ((1f - deadzone) * inputMagnitude);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment