From 794d8bf4aad77a5145280f3ea2adbcefbfbe7434 Mon Sep 17 00:00:00 2001 From: Franklin Blanco Date: Sat, 16 Sep 2023 10:56:24 -0700 Subject: [PATCH] Added aimed sens, aiming in is smooth now, and fixed aim reticles --- src/comps/core/controller.rs | 6 ------ src/constants/player_values.rs | 4 ++-- src/logic/core/guns/spawn_firearm.rs | 1 - src/logic/core/player/camera_player_sync.rs | 18 +++++++++++------- src/logic/core/player/hands.rs | 13 ++++++++++--- src/logic/core/player/player_movement.rs | 9 +-------- 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/comps/core/controller.rs b/src/comps/core/controller.rs index 5b59ca5..1bf224a 100644 --- a/src/comps/core/controller.rs +++ b/src/comps/core/controller.rs @@ -31,8 +31,6 @@ pub fn capture_input( KeyCode::W, KeyCode::C, KeyCode::Space, - KeyCode::Q, - KeyCode::E, ]) || keyboard_input.any_just_released([ KeyCode::A, KeyCode::S, @@ -40,8 +38,6 @@ pub fn capture_input( KeyCode::W, KeyCode::C, KeyCode::Space, - KeyCode::Q, - KeyCode::E, ]) { let player_movement_input = PlayerMovementInput { up: keyboard_input.just_pressed(KeyCode::Space), @@ -51,8 +47,6 @@ pub fn capture_input( front: keyboard_input.pressed(KeyCode::W), back: keyboard_input.pressed(KeyCode::S), sprint: keyboard_input.pressed(KeyCode::ShiftLeft), - lean_left: keyboard_input.pressed(KeyCode::Q), - lean_right: keyboard_input.pressed(KeyCode::E), }; move_player(player_movement_input, player_query, time); } diff --git a/src/constants/player_values.rs b/src/constants/player_values.rs index fa4f4cf..34d4634 100644 --- a/src/constants/player_values.rs +++ b/src/constants/player_values.rs @@ -11,9 +11,9 @@ pub const PLAYER_INITIAL_WEIGHT: f32 = 75.0; pub const PLAYER_GRAVITY_SCALE: f32 = 4.0; pub const PLAYER_HEIGHT: f32 = 2.5; -pub const PLAYER_CAMERA_HEIGHT: f32 = 1.0; +pub const PLAYER_CAMERA_HEIGHT: f32 = 1.25; pub const PLAYER_CROUCH_HEIGHT: f32 = 0.0; -pub const PLAYER_CROUCH_TIME_S: f32 = 0.6; +pub const PLAYER_CROUCH_TIME_S: f32 = 1.25; pub const PLAYER_LINEAR_DAMPING: f32 = 3.5; pub const PLAYER_LINEAR_DAMPING_WHILE_JUMPING: f32 = 0.25; diff --git a/src/logic/core/guns/spawn_firearm.rs b/src/logic/core/guns/spawn_firearm.rs index 0cc6409..5688b0e 100644 --- a/src/logic/core/guns/spawn_firearm.rs +++ b/src/logic/core/guns/spawn_firearm.rs @@ -11,7 +11,6 @@ pub fn spawn_firearm_on_player_hands( asset_server: Res, ) { for entity in query.iter() { - println!("A"); let mut firearm_transform = Transform::from_xyz(0.0, 0.0, 0.0); firearm_transform.rotate_y(utils::rad_deg::radians_from_degrees( DEFAULT_PLAYER_FIREARM.holdable_object_data().y_rot, diff --git a/src/logic/core/player/camera_player_sync.rs b/src/logic/core/player/camera_player_sync.rs index 3355280..5aba2bf 100644 --- a/src/logic/core/player/camera_player_sync.rs +++ b/src/logic/core/player/camera_player_sync.rs @@ -13,13 +13,15 @@ use super::player_movement::PlayerLinearXZState; pub struct MouseMovementSettings { pub sensitivity: f32, pub speed: f32, + pub aimed_sensitivity: f32, } impl Default for MouseMovementSettings { fn default() -> Self { Self { sensitivity: 0.0003, - speed: 12., + speed: 3.0, + aimed_sensitivity: 0.00005, } } } @@ -83,8 +85,14 @@ pub fn follow_cursor_with_camera( let (mut yaw, mut pitch, _) = player_transform.rotation.to_euler(EulerRot::YXZ); for motion in motions.iter() { let window_scale = window.height().min(window.width()); - pitch -= (settings.sensitivity * motion.delta.y * window_scale).to_radians(); - yaw -= (settings.sensitivity * motion.delta.x * window_scale).to_radians(); + if btn.pressed(MouseButton::Right) { + pitch -= (settings.aimed_sensitivity * motion.delta.y * window_scale).to_radians(); + yaw -= (settings.aimed_sensitivity * motion.delta.x * window_scale).to_radians(); + } else { + pitch -= (settings.sensitivity * motion.delta.y * window_scale).to_radians(); + yaw -= (settings.sensitivity * motion.delta.x * window_scale).to_radians(); + } + } pitch = pitch.clamp(-1.54, 1.54); @@ -111,7 +119,3 @@ pub fn follow_cursor_with_camera( warn!("Primary window not found for `player_look`!"); } } - -fn lerp(final_vec: Vec3, current: Vec3, delta_time: f32, total_time: f32) -> Vec3 { - (final_vec - current) * (delta_time/total_time) -} diff --git a/src/logic/core/player/hands.rs b/src/logic/core/player/hands.rs index 33363c8..cc31cd2 100644 --- a/src/logic/core/player/hands.rs +++ b/src/logic/core/player/hands.rs @@ -5,7 +5,7 @@ use crate::comps::core::markers::player::PlayerHand; pub fn capture_hand_usage( mouse_buttons: Res>, mut query: Query<&mut Transform, With>, - //time: Res