Skip to content

Make axis strength always be positive#17

Open
johanhelsing wants to merge 1 commit intolightsoutgames:mainfrom
johanhelsing:consistent-axis-strength
Open

Make axis strength always be positive#17
johanhelsing wants to merge 1 commit intolightsoutgames:mainfrom
johanhelsing:consistent-axis-strength

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