Skip to content

ButtonInput not working for some combinations #17995

Open
@bbasics

Description

@bbasics

Bevy version

bevy = { version = "0.15", features = ["dynamic_linking"] }
bevy_panorbit_camera = "0.23.0"
bevy_rapier3d = "0.29.0"

[Optional] Relevant system information

Ubuntu 24.04.2 LTS

cargo 1.85.0 (d73d2caf9 2024-12-31)

What you did

I got a player controller, but when I try to jump while pressing ArrowUp + ArrowLeft + Space it does not jump. However it does work when I press any other combination (e.g. ArrowUp + ArrowRight + Space). The weird part is that it does the same on the second player with KeyW + KeyA + KeyQ. It does look into a bug on my side but if I map the jump to KeyP for instance, it works well.

impl Team {
    fn get_key_map(&self) -> KeyMap {
        match self {
            Self::Blue => KeyMap {
                jump: KeyCode::Space,
                left: KeyCode::ArrowLeft,
                right: KeyCode::ArrowRight,
                up: KeyCode::ArrowUp,
                down: KeyCode::ArrowDown,
            },
            Self::Red => KeyMap {
                jump: KeyCode::KeyQ,
                left: KeyCode::KeyA,
                right: KeyCode::KeyD,
                up: KeyCode::KeyW,
                down: KeyCode::KeyS,
            },
        }
    }
}

fn inputs_system(
    keys: Res<ButtonInput<KeyCode>>,
    mut players: Query<(&mut Player, &KinematicCharacterControllerOutput)>,
) {
    const SPEED: f32 = 3.0;
    for (mut player, output) in players.iter_mut() {
        player.direction = Vec2::ZERO;
        let key_map = player.team.get_key_map();

        if keys.just_pressed(key_map.jump) && output.grounded {
            player.vertical_velocity = 0.5 * GRAVITY;
        }
        player.direction = Vec2::ZERO;
        if keys.pressed(key_map.left) {
            player.direction.x = -SPEED;
        }
        if keys.pressed(key_map.right) {
            player.direction.x = SPEED;
        }
        if keys.pressed(key_map.up) {
            player.direction.y = -SPEED;
        }
        if keys.pressed(key_map.down) {
            player.direction.y = SPEED;
        }
    }
}

pressed instead of just_pressed does the same thing.

I'm just starting bevy, like from yesterday. I could have missed something.

Thanks everyone

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-InputPlayer input via keyboard, mouse, gamepad, and moreC-BugAn unexpected or incorrect behaviorS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions