Skip to content

Commit

Permalink
Add cursor grab on FlyCam spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
askor committed Feb 7, 2023
1 parent 98050cb commit 702b2e4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ fn cursor_grab(keys: Res<Input<KeyCode>>, mut windows: ResMut<Windows>) {
}
}

// Grab cursor when an entity with FlyCam is added
fn initial_grab_on_flycam_spawn(mut windows: ResMut<Windows>, query_added: Query<Entity, Added<FlyCam>>) {
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 {
Expand All @@ -171,7 +182,7 @@ impl Plugin for NoCameraPlayerPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<InputState>()
.init_resource::<MovementSettings>()
.add_startup_system(initial_grab_cursor)
.add_system(initial_grab_on_flycam_spawn)
.add_system(player_move)
.add_system(player_look)
.add_system(cursor_grab);
Expand Down

0 comments on commit 702b2e4

Please sign in to comment.