generated from 2ndbeam/bevy-template
feat: Basic player implementation
This commit is contained in:
parent
62199a1817
commit
e4b1475c48
9 changed files with 830 additions and 54 deletions
25
src/player/systems.rs
Normal file
25
src/player/systems.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
//! 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.;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue