fix look around with gamepad

This commit is contained in:
2025-03-20 17:59:54 +01:00
parent 1721a34249
commit cd81f4260d
3 changed files with 46 additions and 9 deletions

View File

@@ -56,7 +56,7 @@ pub fn plugin(app: &mut App) {
apply_controls.in_set(TnuaUserControlsSystemSet),
);
app.add_systems(Update, rotate_view);
app.add_systems(Update, (rotate_view_keyboard, rotate_view_gamepad));
app.add_observer(update_head);
}
@@ -126,7 +126,25 @@ fn spawn(
player_spawned.spawned = true;
}
fn rotate_view(
fn rotate_view_gamepad(
controls: Res<Controls>,
// todo: Put the player head as a child of the rig to avoid this mess:
mut player: Query<&mut Transform, With<PlayerRig>>,
) {
let Some(gamepad) = controls.gamepad_state else {
return;
};
if gamepad.view_mode {
return;
}
for mut tr in &mut player {
tr.rotate_y(gamepad.look_dir.x * -0.001);
}
}
fn rotate_view_keyboard(
mut controls: ResMut<Controls>,
// todo: Put the player head as a child of the rig to avoid this mess:
mut player: Query<&mut Transform, With<PlayerRig>>,
@@ -137,10 +155,6 @@ fn rotate_view(
for mut tr in &mut player {
tr.rotate_y(controls.keyboard_state.look_dir.x * -0.001);
if let Some(gamepad) = controls.gamepad_state {
tr.rotate_y(gamepad.look_dir.x * -0.001);
}
}
controls.keyboard_state.look_dir = Vec2::ZERO;