use bevy::{input::mouse::MouseMotion, prelude::*}; #[derive(Component)] pub struct FlyCamera { pub accel: f32, pub max_speed: f32, pub sensitivity: f32, pub friction: f32, pub yaw_pitch: Option<(f32, f32)>, pub velocity: Vec3, pub key_forward: KeyCode, pub key_backward: KeyCode, pub key_left: KeyCode, pub key_right: KeyCode, pub key_up: KeyCode, pub key_down: KeyCode, pub enabled: bool, pub mouse_motion_enabled: bool, } impl Default for FlyCamera { fn default() -> Self { Self { accel: 1.5, max_speed: 0.5, sensitivity: 3.0, friction: 1.0, yaw_pitch: None, velocity: Vec3::ZERO, key_forward: KeyCode::W, key_backward: KeyCode::S, key_left: KeyCode::A, key_right: KeyCode::D, key_up: KeyCode::Space, key_down: KeyCode::ShiftLeft, enabled: true, mouse_motion_enabled: true, } } } fn forward_vector(rotation: &Quat) -> Vec3 { rotation.mul_vec3(Vec3::Z).normalize() } fn forward_walk_vector(rotation: &Quat) -> Vec3 { let f = forward_vector(rotation); let f_flattened = Vec3::new(f.x, 0.0, f.z).normalize(); f_flattened } fn strafe_vector(rotation: &Quat) -> Vec3 { Quat::from_rotation_y(90.0f32.to_radians()) .mul_vec3(forward_walk_vector(rotation)) .normalize() } fn camera_movement_system( time: Res