diff --git a/src/lib.rs b/src/lib.rs
index 19d63e1..5741541 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -220,6 +220,17 @@ fn cursor_grab(keys: Res>, mut windows: ResMut) {
}
}
+// Grab cursor when an entity with FlyCam is added
+fn initial_grab_on_flycam_spawn(mut windows: ResMut, query_added: Query>) {
+ if query_added.is_empty() { return; }
+
+ if let Some(window) = windows.get_primary_mut() {
+ toggle_grab_cursor(window);
+ } else {
+ warn!("Primary window not found for `initial_grab_cursor`!");
+ }
+}
+
/// Contains everything needed to add first-person fly camera behavior to your game
pub struct PlayerPlugin;
impl Plugin for PlayerPlugin {
@@ -246,6 +257,7 @@ impl Plugin for NoCameraPlayerPlugin {
fn build(&self, app: &mut App) {
app.init_resource::()
.init_resource::()
+ .add_system(initial_grab_on_flycam_spawn)
.add_system(initial_grab_cursor.on_startup())
.add_system(player_move)
.add_system(player_look)