Skip to content

Handle deadzones "correctly" #3691

@alice-i-cecile

Description

@alice-i-cecile

Problem

Gamepad axis deadzone handling is a mess. Our current solution is an extremely naive, unscaled axial approach.

Users can control the dead zone size, but not the behavior.

Proposed Solution

  1. Use an enum to allow configuration between raw (no deadzone), axial and radial deadzones.
  2. Use a second enum to allow the falloff curve to be configured: raw, linear, or custom. Other than for the raw passthrough feedback curve, the values here should always be in [0, 1].
  3. Use linearly rescaled radial deadzones by default.
  4. Ensure that we have a configurable threshold for both the inner and outer values.
  5. Ensure that Bevy users can still easily access the raw axis values no matter which configuration mode they're using.
enum DeadzoneShape {
  None,
  Axial(DeadzoneRescaling).
  Radial(DeadzoneRescaling),
}

// Maps from the raw axis input values received
// into the input values observed in `Input<GamepadAxis>`
// The input is in the range [-1, 1]
// The output should also be in the range [-1, 1]
enum DeadzoneRescaling {
  Raw,
  Linear,
  Custom(Fn(f32) -> f32),
}

Additional context

#3450 and the associated #3464 are an initial attempt at handling falloff curves. This work should be coordinated with that work, one way or another.

xinput.h defines some constants they expect you to use for your deadzone... N.B. someone will complain these are too small to be reasonable defaults, and someone else will complain they are too large. I've seen at least one controller worn out enough to drift with defaults. So you'll probably want some kind of scaling option. Oh, and the outer limits may or may not be the integer max. Depends on the controller. And some weirdos like the axial dead zones weird cross shaped deadzone nonsense. And then they'll have strong opinions about the falloff curve from inner to outer - should it be linear? squared? cubed?

  • MaulingMonkey from the Rust Gamedev Discord <3

Additional in-depth opinions from Third Helix

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-InputPlayer input via keyboard, mouse, gamepad, and moreC-UsabilityA targeted quality-of-life change that makes Bevy easier to useD-TrivialNice and easy! A great choice to get started with Bevy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions