Simplify working with controls (#27)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use super::{ControllerSet, Controls, controller_common::MovementSpeedFactor};
|
||||
use super::{ControlState, ControllerSet, Controls, controller_common::MovementSpeedFactor};
|
||||
use crate::{GameState, player::PlayerBodyMesh};
|
||||
use avian3d::{math::*, prelude::*};
|
||||
use bevy::{ecs::query::Has, prelude::*};
|
||||
@@ -19,8 +19,7 @@ impl Plugin for CharacterControllerPlugin {
|
||||
set_movement_flag,
|
||||
update_grounded,
|
||||
apply_gravity,
|
||||
rotate_view_keyboard,
|
||||
rotate_view_gamepad, // todo consider merging these two
|
||||
rotate_view,
|
||||
movement,
|
||||
)
|
||||
.chain()
|
||||
@@ -77,38 +76,19 @@ fn set_movement_flag(mut player_movement: ResMut<PlayerMovement>, controls: Res<
|
||||
}
|
||||
}
|
||||
|
||||
fn rotate_view_gamepad(
|
||||
controls: Res<Controls>,
|
||||
fn rotate_view(
|
||||
controls: Res<ControlState>,
|
||||
mut player: Query<&mut Transform, With<PlayerBodyMesh>>,
|
||||
) {
|
||||
let Some(gamepad) = controls.gamepad_state else {
|
||||
return;
|
||||
};
|
||||
|
||||
if gamepad.view_mode {
|
||||
if controls.view_mode {
|
||||
return;
|
||||
}
|
||||
|
||||
for mut tr in &mut player {
|
||||
tr.rotate_y(gamepad.look_dir.x * -0.001);
|
||||
tr.rotate_y(controls.look_dir.x * -0.001);
|
||||
}
|
||||
}
|
||||
|
||||
fn rotate_view_keyboard(
|
||||
mut controls: ResMut<Controls>,
|
||||
mut player: Query<&mut Transform, With<PlayerBodyMesh>>,
|
||||
) {
|
||||
if controls.keyboard_state.view_mode {
|
||||
return;
|
||||
}
|
||||
|
||||
for mut tr in &mut player {
|
||||
tr.rotate_y(controls.keyboard_state.look_dir.x * -0.001);
|
||||
}
|
||||
|
||||
controls.keyboard_state.look_dir = Vec2::ZERO;
|
||||
}
|
||||
|
||||
/// Responds to [`MovementAction`] events and moves character controllers accordingly.
|
||||
fn movement(
|
||||
controls: Res<Controls>,
|
||||
|
||||
Reference in New Issue
Block a user