generated from 2ndbeam/bevy-template
25 lines
625 B
Rust
25 lines
625 B
Rust
//! Player systems
|
|
|
|
use super::*;
|
|
|
|
/// Do something based on [PlayerInput]
|
|
pub fn handle_input(
|
|
time: Res<Time>,
|
|
|
|
player_query: Query<(
|
|
&Player,
|
|
&ActionState<PlayerInput>,
|
|
&mut KinematicCharacterController,
|
|
&mut Sprite,
|
|
)>,
|
|
) {
|
|
for (player, action_state, mut controller, mut sprite) in player_query {
|
|
let direction = action_state.clamped_value(&PlayerInput::Move);
|
|
|
|
controller.translation = Some(vec2(direction * player.speed * time.delta_secs(), 0.));
|
|
|
|
if direction != 0. {
|
|
sprite.flip_x = direction < 0.;
|
|
}
|
|
}
|
|
}
|