Skip to content

Scale input to account for deadzones#17015

Merged
alice-i-cecile merged 8 commits intobevyengine:mainfrom
BenjaminBrienen:scaled-deadzones
Jan 3, 2025
Merged

Scale input to account for deadzones#17015
alice-i-cecile merged 8 commits intobevyengine:mainfrom
BenjaminBrienen:scaled-deadzones

Conversation

@BenjaminBrienen
Copy link
Copy Markdown
Contributor

@BenjaminBrienen BenjaminBrienen commented Dec 29, 2024

Objective

Fixes #3450

Solution

Scale the input to account for the range

Testing

Updated unit tests

Migration Guide

GamepadButtonChangedEvent.value is now linearly rescaled to be from 0.0..=1.0 (instead of low..=high) and GamepadAxisChangedEvent.value is now linearly rescaled to be from -1.0..=0.0/0.0..=1.0 (accounting for the deadzone).

@BenjaminBrienen BenjaminBrienen self-assigned this Dec 29, 2024
@BenjaminBrienen BenjaminBrienen added A-Input Player input via keyboard, mouse, gamepad, and more D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Dec 29, 2024
@BenjaminBrienen
Copy link
Copy Markdown
Contributor Author

I can't work on fixing the unit tests until this is fixed:

error[E0599]: no method named `to_string` found for reference `&str` in the current scope
   --> crates\bevy_ecs\src\name.rs:252:24
    |
252 |         Ok(Name::new(v.to_string()))
    |                        ^^^^^^^^^ method not found in `&str`
    |
    = help: items from traits can only be used if the trait is in scope
help: trait `ToString` which provides `to_string` is implemented but not in scope; perhaps you want to import it
    |
3   + use crate::alloc::string::ToString;

Copy link
Copy Markdown
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this is the right default behavior. Otherwise setting a deadzone makes it very hard / impossible to get small directional inputs.

This PR needs a bit of cleanup still. It would be particularly helpful to cleanup the tests: right now, the values just look like magic numbers. Maybe we should add some algebra + consts inside of the Some arms?

@alice-i-cecile
Copy link
Copy Markdown
Member

For the alloc error, I think you need to fix the feature flags in a new PR. @bushrat011899, FYI.

@BenjaminBrienen
Copy link
Copy Markdown
Contributor Author

BenjaminBrienen commented Dec 29, 2024

For the alloc error, I think you need to fix the feature flags in a new PR. @bushrat011899, FYI.

He's already got that fixed in the no_std bevy_input PR.

@bushrat011899
Copy link
Copy Markdown
Contributor

Can confirm I have this issue resolved in the no_std bevy_input PR, along with some other issues with how bevy_input feature gates bevy_reflect

@BenjaminBrienen BenjaminBrienen force-pushed the scaled-deadzones branch 2 times, most recently from 3eac744 to 91be8f2 Compare December 30, 2024 05:16
@alice-i-cecile alice-i-cecile added the M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Dec 30, 2024
@github-actions
Copy link
Copy Markdown
Contributor

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy?
It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

@alice-i-cecile
Copy link
Copy Markdown
Member

Let's do a quick migration guide noting this change (since it's otherwise surprising), but this LGTM now. Good work on the tests; I like the balance you struck.

@BenjaminBrienen
Copy link
Copy Markdown
Contributor Author

Sorry for the noise. I realized that I could make the implementation and test data cleaner by storing the raw values in the gamepad, which means the old values will be raw values. Everything is very optimal now, imo.

@BenjaminBrienen
Copy link
Copy Markdown
Contributor Author

Migration guide made me realize the doc comment should be improved. Both are done now.

Copy link
Copy Markdown
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the latest changes, and particularly appreciate the comments on the tests.

Copy link
Copy Markdown
Contributor

@Shatur Shatur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Left a few small suggestions.

Personally, I think deadzone is a more high-level functionality and should be handled by input managers🤔 But since we already have this feature, it's definitely an improvement!
I handle deadzones in the same way in the bevy_enhanced_input library.

@alice-i-cecile
Copy link
Copy Markdown
Member

Personally, I think deadzone is a more high-level functionality and should be handled by input managers

Agreed. In the medium term, I think this functionality should be removed from bevy_input and moved up a level. But until we have a first party input manager / action crate we're blocked there.

@BenjaminBrienen
Copy link
Copy Markdown
Contributor Author

BenjaminBrienen commented Dec 30, 2024

I think deadzones and scaling are good here because they address hardware limitations. Before then, the events are "raw". The part I would move into another crate is actually the clamping/rounding. Those are more about what "feels right". But then again, the same applies for the press/release/change thresholds, and I don't think those can be moved out.

@Shatur
Copy link
Copy Markdown
Contributor

Shatur commented Dec 30, 2024

I would consider bevy_input as a source for raw input and its processing being a higher-level abstraction. That's what I currently do with my crate (I use methods that return raw values and let user apply any modifiers on top of them).

We on the same page with @alice-i-cecile, this PR is good.
I just wanted to share my thoughts for possible future considerations.

@BenjaminBrienen BenjaminBrienen added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 1, 2025
@BenjaminBrienen BenjaminBrienen requested a review from Shatur January 3, 2025 21:49
@BenjaminBrienen
Copy link
Copy Markdown
Contributor Author

I'm choosing to not split up the unit test. It can be done as an improvement in a separate PR if someone would like. :)

@BenjaminBrienen BenjaminBrienen added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jan 3, 2025
@BenjaminBrienen BenjaminBrienen added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 3, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 3, 2025
Merged via the queue into bevyengine:main with commit 43db44c Jan 3, 2025
mrchantey pushed a commit to mrchantey/bevy that referenced this pull request Feb 4, 2025
# Objective

Fixes bevyengine#3450 

## Solution

Scale the input to account for the range

## Testing

Updated unit tests

## Migration Guide

`GamepadButtonChangedEvent.value` is now linearly rescaled to be from
`0.0..=1.0` (instead of `low..=high`) and
`GamepadAxisChangedEvent.value` is now linearly rescaled to be from
`-1.0..=0.0`/`0.0..=1.0` (accounting for the deadzone).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Input Player input via keyboard, mouse, gamepad, and more C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deadzone clipping in AxisSettings and ButtonSettings results in a compression of values

4 participants