From 5566d73d9e49be09f8e85b546b8102b0841ae1c0 Mon Sep 17 00:00:00 2001 From: Aceeri Date: Tue, 27 Dec 2022 00:34:06 +0000 Subject: [PATCH] Nicer usage for scene viewer (#7035) # Objective Scene viewer mouse sensitivity/cursor usage isn't the best it could be atm, so just adding some quick, maybe opinionated, tweaks to make it feel more at home in usage. ## Solution - Mouse delta shouldn't be affected by delta time, it should be more expected that if I move my mouse 1 inch to the right that it should move the in game camera/whatever is controlled the same regardless of FPS. - Uses a magic number of 180.0 for a nice default sensitivity, modeled after Valorant's default sensitivity. - Cursor now gets locked/hidden when rotating the camera to give it more of the effect that you are grabbing the camera. --- .../scene_viewer/camera_controller_plugin.rs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/examples/tools/scene_viewer/camera_controller_plugin.rs b/examples/tools/scene_viewer/camera_controller_plugin.rs index 3ee15c06fb..5ebbc43dd6 100644 --- a/examples/tools/scene_viewer/camera_controller_plugin.rs +++ b/examples/tools/scene_viewer/camera_controller_plugin.rs @@ -3,11 +3,17 @@ //! - 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::window::CursorGrabMode; use bevy::{input::mouse::MouseMotion, prelude::*}; use std::f32::consts::*; use std::fmt; +/// Based on Valorant's default sensitivity, not entirely sure why it is exactly 1.0 / 180.0, +/// but I'm guessing it is a misunderstanding between degrees/radians and then sticking with +/// it because it felt nice. +pub const RADIANS_PER_DOT: f32 = 1.0 / 180.0; + #[derive(Component)] pub struct CameraController { pub enabled: bool, @@ -35,7 +41,7 @@ impl Default for CameraController { Self { enabled: true, initialized: false, - sensitivity: 0.5, + sensitivity: 1.0, key_forward: KeyCode::W, key_back: KeyCode::S, key_left: KeyCode::A, @@ -91,12 +97,14 @@ impl Plugin for CameraControllerPlugin { fn camera_controller( time: Res