Skip to content
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

Press duration example not working - Previous Duration and Current Duration methods always return zero #127

Closed
Redwoodstudio opened this issue Apr 20, 2022 · 6 comments
Labels
bug Something isn't working
Milestone

Comments

@Redwoodstudio
Copy link

Version

0.3.0
Bevy 0.7.0

Operating system & version

Windows 10

What you did

I tried running the press_duration example.

What you expected to happen

From my understating, the player object should "leap" when the left/right key is released, with the leap distance dependent on the length of the keypress.

What actually happened

The player object didn't move at all.

Additional information

I've narrowed down the problem to the previous_duration and the current_duration functions always returning zero.

A minimal example of the issue (edited minimal example)

use bevy::prelude::*;
use leafwing_input_manager::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(InputManagerPlugin::<Action>::default())
        .add_startup_system(spawn_player)
        .add_system(jump)
        .run();
}

#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug)]
enum Action {
    Run,
    Jump,
}

#[derive(Component)]
struct Player;

fn spawn_player(mut commands: Commands) {
    commands
        .spawn()
        .insert(Player)
        .insert_bundle(InputManagerBundle::<Action> {
            action_state: ActionState::default(),
            input_map: InputMap::new([(Action::Jump, KeyCode::Space)]),
        });
}
fn jump(query: Query<&ActionState<Action>, With<Player>>) {
    let action_state = query.single();
    if action_state.just_released(Action::Jump) {
        info!("End jump time: {:?}", action_state.previous_duration(Action::Jump));
    }
    if action_state.pressed(Action::Jump) {
        info!("Current jump time: {:?}", action_state.current_duration(Action::Jump));
    }
    if action_state.just_pressed(Action::Jump) {
        info!("Started jump!");
    }
}
@Redwoodstudio Redwoodstudio added the bug Something isn't working label Apr 20, 2022
@alice-i-cecile
Copy link
Contributor

Thanks for the report. I'll take a look! Tests are passing, so something funky must be going on...

@krojew
Copy link

krojew commented Apr 21, 2022

Can confirm - they are always 0.

@alice-i-cecile
Copy link
Contributor

Examining this today :)

@alice-i-cecile
Copy link
Contributor

This is a bug in the library, not the example. Going to fix and release ASAP.

@alice-i-cecile alice-i-cecile added this to the 0.3.1 milestone Jun 2, 2022
@alice-i-cecile
Copy link
Contributor

This was so, so much harder to fix than I expected. Sorry about the wait!

@Redwoodstudio
Copy link
Author

Awesome, thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants