2023-09-12 04:47:37 +00:00
|
|
|
use bevy::prelude::*;
|
|
|
|
use bevy_rapier3d::prelude::*;
|
|
|
|
|
2023-09-12 13:58:58 +00:00
|
|
|
use crate::logic::core::player::player_movement::{PlayerMovementInput, move_player, PlayerLinearYState};
|
2023-09-12 04:47:37 +00:00
|
|
|
|
|
|
|
use super::markers::player::Player;
|
|
|
|
|
|
|
|
/// System that captures input and fires events
|
2023-09-12 13:58:58 +00:00
|
|
|
pub fn capture_input(keyboard_input: Res<Input<KeyCode>>, query: Query<(&mut Velocity, &mut ExternalImpulse, &mut PlayerLinearYState), With<Player>>, time: Res<Time>) {
|
2023-09-12 04:47:37 +00:00
|
|
|
// Don't allocate on each frame. Instead Check if any of the inputs are being pressed and then allocate.
|
|
|
|
if keyboard_input.any_pressed([KeyCode::A, KeyCode::S, KeyCode::D, KeyCode::W, KeyCode::C, KeyCode::Space]) {
|
|
|
|
let player_movement_input = PlayerMovementInput {
|
2023-09-12 14:03:33 +00:00
|
|
|
up: keyboard_input.just_pressed(KeyCode::Space),
|
2023-09-12 04:47:37 +00:00
|
|
|
down: keyboard_input.pressed(KeyCode::C),
|
|
|
|
left: keyboard_input.pressed(KeyCode::A),
|
|
|
|
right: keyboard_input.pressed(KeyCode::D),
|
|
|
|
front: keyboard_input.pressed(KeyCode::W),
|
|
|
|
back: keyboard_input.pressed(KeyCode::S),
|
|
|
|
sprint: keyboard_input.pressed(KeyCode::ShiftLeft),
|
|
|
|
};
|
|
|
|
move_player(player_movement_input, query, time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|