Skip to content

Make axis strength always be positive #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

johanhelsing
Copy link
Contributor

Since an analog stick is split into four different inputs (i.e. negative x) it made more sense to me that the strength should always go from 0 to 1 regardless of which of the four directions it is.

How I use it in my own code:

pub trait AxisInput {
    fn horizontal(&self) -> f32;
}

impl AxisInput for InputMap<Action> {
    fn horizontal(&self) -> f32 {
        -self.strength(Action::Left) + self.strength(Action::Right)
    }
}

pub fn read_inputs(mut query: Query<&mut Player>, input_map: Res<InputMap<Action>>) {
    let horizontal = input_map.horizontal();
    // ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant