From 490fef5393b1b0842f7313b9a8ba061ca782f01c Mon Sep 17 00:00:00 2001 From: Robert Fry Date: Tue, 7 Jan 2025 14:15:37 +0000 Subject: [PATCH] fix: player fires bullets only when cursor grabbed --- src/game/player.rs | 6 +++++- src/main.rs | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/game/player.rs b/src/game/player.rs index d1b4396..b364f24 100644 --- a/src/game/player.rs +++ b/src/game/player.rs @@ -5,6 +5,7 @@ use avian3d::prelude::*; use crate::physics::BulletFiredEvent; use crate::ui::camera::CameraController; +use crate::ui::cursor::CursorGrabState; pub struct PlayerPlugin; @@ -13,7 +14,10 @@ impl Plugin for PlayerPlugin fn build(&self, app: &mut App) { app.add_systems(Startup, setup_player); - app.add_systems(PreUpdate, do_shoot_on_left_click.run_if(on_event::)); + app.add_systems(Update, do_shoot_on_left_click + .run_if(in_state(CursorGrabState(true))) + .run_if(on_event::) + ); } } diff --git a/src/main.rs b/src/main.rs index 0ded365..fecfd8a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ fn main() { let mut app = App::new(); app.add_plugins(DefaultPlugins); + app.add_plugins(util::UtilPlugins); app.add_plugins(ui::UiPlugins); app.add_plugins(physics::PhysicsPlugins); app.add_plugins(game::GamePlugin);