use bevy::app::{Events, ManualEventReader}; use bevy::input::mouse::MouseMotion; use bevy::prelude::*; // stolen with neither shame nor pity from git@github.com:sburris0/bevy_flycam.git, b90f6fc, which is copyright 2020 Spencer Burris /// Keeps track of mouse motion events, pitch, and yaw #[derive(Default)] struct InputState { reader_motion: ManualEventReader, pitch: f32, yaw: f32, } /// Mouse sensitivity and movement speed pub struct MovementSettings { pub sensitivity: f32, pub speed: f32, } impl Default for MovementSettings { fn default() -> Self { Self { sensitivity: 0.00012, speed: 12., } } } /// Used in queries when you want flycams and not other cameras #[derive(Debug, Component)] pub struct FlyCam; /// Grabs/ungrabs mouse cursor fn toggle_grab_cursor(window: &mut Window) { window.set_cursor_lock_mode(!window.cursor_locked()); window.set_cursor_visibility(!window.cursor_visible()); } /// Grabs the cursor when game first starts fn initial_grab_cursor(mut windows: ResMut) { toggle_grab_cursor(windows.get_primary_mut().unwrap()); } /// Spawns the `Camera3dBundle` to be controlled fn setup_player(mut commands: Commands) { commands .spawn_bundle(PerspectiveCameraBundle { transform: Transform::from_xyz(-2.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y), ..Default::default() }) .insert(FlyCam); } /// Handles keyboard input and movement fn player_move( keys: Res>, time: Res