diff --git a/src/player.rs b/src/player.rs index 688a287..fd3bc4e 100644 --- a/src/player.rs +++ b/src/player.rs @@ -13,6 +13,7 @@ use avian3d::{ prelude::*, }; use bevy::{ + input::common_conditions::input_just_pressed, prelude::*, window::{CursorGrabMode, PrimaryWindow}, }; @@ -38,7 +39,7 @@ struct PlayerSpawned { pub fn plugin(app: &mut App) { app.init_resource::(); - app.add_systems(Startup, (initial_grab_cursor, cursor_recenter)); + app.add_systems(Startup, (toggle_cursor_system, cursor_recenter)); app.add_systems( Update, ( @@ -46,6 +47,7 @@ pub fn plugin(app: &mut App) { collect_cash, toggle_animation, setup_animations_marker_for_player, + toggle_cursor_system.run_if(input_just_pressed(KeyCode::Escape)), ), ); @@ -128,7 +130,6 @@ fn spawn( fn rotate_view_gamepad( controls: Res, - // todo: Put the player head as a child of the rig to avoid this mess: mut player: Query<&mut Transform, With>, ) { let Some(gamepad) = controls.gamepad_state else { @@ -146,7 +147,6 @@ fn rotate_view_gamepad( fn rotate_view_keyboard( mut controls: ResMut, - // todo: Put the player head as a child of the rig to avoid this mess: mut player: Query<&mut Transform, With>, ) { if controls.keyboard_state.view_mode { @@ -179,11 +179,11 @@ fn toggle_grab_cursor(window: &mut Window) { } } -fn initial_grab_cursor(mut primary_window: Query<&mut Window, With>) { +fn toggle_cursor_system(mut primary_window: Query<&mut Window, With>) { if let Ok(mut window) = primary_window.get_single_mut() { toggle_grab_cursor(&mut window); } else { - warn!("Primary window not found for `initial_grab_cursor`!"); + warn!("Primary window not found for `toggle_cursor_system`!"); } }