bevyengine / bevyengine/bevy

Handle deadzones "correctly"

Open
#3,691 4 comments 1 reaction 0 assignees View on GitHub
A-Input C-Usability D-Modest S-Needs-Design X-Contentious
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## 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.

```rust
enum DeadzoneShape {
None,
Axial(DeadzoneRescaling).
Radial(DeadzoneRescaling),
}

// Maps from the raw axis input values received
// into the input values observed in `Input`
// 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](https://web.archive.org/web/20141025190105/https://www.third-helix.com/2013/04/12/doing-thumbstick-dead-zones-right.html)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.