diff --git a/examples/camera/first_person_view_model.rs b/examples/camera/first_person_view_model.rs index d2e6c24373..9a91eb324b 100644 --- a/examples/camera/first_person_view_model.rs +++ b/examples/camera/first_person_view_model.rs @@ -43,7 +43,7 @@ //! | arrow down | Increase FOV | use bevy::color::palettes::tailwind; -use bevy::input::mouse::MouseMotion; +use bevy::input::mouse::AccumulatedMouseMotion; use bevy::pbr::NotShadowCaster; use bevy::prelude::*; use bevy::render::view::RenderLayers; @@ -219,13 +219,15 @@ fn spawn_text(mut commands: Commands) { } fn move_player( - mut mouse_motion: EventReader, + accumulated_mouse_motion: Res, mut player: Query<&mut Transform, With>, ) { let mut transform = player.single_mut(); - for motion in mouse_motion.read() { - let yaw = -motion.delta.x * 0.003; - let pitch = -motion.delta.y * 0.002; + let delta = accumulated_mouse_motion.delta; + + if delta != Vec2::ZERO { + let yaw = -delta.x * 0.003; + let pitch = -delta.y * 0.002; // Order of rotations is important, see transform.rotate_y(yaw); transform.rotate_local_x(pitch); diff --git a/examples/helpers/camera_controller.rs b/examples/helpers/camera_controller.rs index 75e428aa3e..86defefb90 100644 --- a/examples/helpers/camera_controller.rs +++ b/examples/helpers/camera_controller.rs @@ -3,7 +3,7 @@ //! - Copy the code for the [`CameraControllerPlugin`] and add the plugin to your App. //! - Attach the [`CameraController`] component to an entity with a [`Camera3dBundle`]. -use bevy::input::mouse::{MouseMotion, MouseScrollUnit, MouseWheel}; +use bevy::input::mouse::{AccumulatedMouseMotion, AccumulatedMouseScroll, MouseScrollUnit}; use bevy::prelude::*; use bevy::window::CursorGrabMode; use std::{f32::consts::*, fmt}; @@ -101,8 +101,8 @@ Freecam Controls: fn run_camera_controller( time: Res