You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
873 B
30 lines
873 B
use bevy::prelude::*; |
|
use common::prelude::*; |
|
use lightyear::prelude::input::native::*; |
|
|
|
use bevy::input::mouse::AccumulatedMouseMotion; |
|
|
|
use crate::input::is_cursor_grabbed; |
|
|
|
#[derive(Resource, Deref, DerefMut, Debug)] |
|
pub struct MouseSensitivity(Vec2); |
|
|
|
impl Default for MouseSensitivity { |
|
fn default() -> Self { |
|
Self(Vec2::splat(0.2).map(f32::to_radians)) |
|
} |
|
} |
|
|
|
pub fn plugin(app: &mut App) { |
|
app.init_resource::<MouseSensitivity>(); |
|
app.add_systems(Update, update_head_orientation.run_if(is_cursor_grabbed)); |
|
} |
|
|
|
fn update_head_orientation( |
|
accumulated_mouse_motion: Res<AccumulatedMouseMotion>, |
|
mouse_sensitivity: Res<MouseSensitivity>, |
|
mut orientation: Single<&mut HeadOrientation, With<InputMarker<Inputs>>>, |
|
) { |
|
let delta = accumulated_mouse_motion.delta * **mouse_sensitivity; |
|
**orientation = orientation.update(delta); |
|
}
|
|
|