From e362d6f9fa4af05e13182890de48f25844eefce0 Mon Sep 17 00:00:00 2001 From: Franklin Date: Wed, 13 Sep 2023 11:56:42 -0400 Subject: [PATCH] Added smooth crouch downards --- Readme.md | 2 +- src/comps/core/controller.rs | 2 +- src/constants/player_values.rs | 3 +- src/logic/core/player/camera_player_sync.rs | 14 ++++++-- src/logic/core/player/player_movement.rs | 37 +++++++++++---------- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/Readme.md b/Readme.md index 8bb70fc..45e597a 100644 --- a/Readme.md +++ b/Readme.md @@ -4,7 +4,7 @@ - [x] ~~Glitch: Fall does not remove linear damping, only after jump~~ - [x] ~~Glitch: Negative linear damping on jump allows for bunny hopping~~ -- [ ] Feature: Add smooth camera movement to camera on crouch. Right now it's too fast and looks arcade af. +- [x] Feature: Add smooth camera movement to camera on crouch. Right now it's too fast and looks arcade af. - [ ] Feature: Add jump effect to camera - [ ] Feature: Add Stamina (with bar?) - [ ] Feature: Subtle Headbob, FOV change on movement (Distinguish between sprinting and walking). diff --git a/src/comps/core/controller.rs b/src/comps/core/controller.rs index 1258e35..b5897c1 100644 --- a/src/comps/core/controller.rs +++ b/src/comps/core/controller.rs @@ -41,7 +41,7 @@ pub fn capture_input( ]) { let player_movement_input = PlayerMovementInput { up: keyboard_input.just_pressed(KeyCode::Space), - down: keyboard_input.pressed(KeyCode::C), + down: keyboard_input.just_pressed(KeyCode::C), left: keyboard_input.pressed(KeyCode::A), right: keyboard_input.pressed(KeyCode::D), front: keyboard_input.pressed(KeyCode::W), diff --git a/src/constants/player_values.rs b/src/constants/player_values.rs index 943f06e..60554ab 100644 --- a/src/constants/player_values.rs +++ b/src/constants/player_values.rs @@ -8,9 +8,10 @@ pub const PLAYER_CROUCH_SPEED_MULTIPLIER: f32 = 0.25; pub const PLAYER_INITIAL_WEIGHT: f32 = 75.0; pub const PLAYER_GRAVITY_SCALE: f32 = 4.0; -pub const PLAYER_HEIGHT: f32 = 2.0; +pub const PLAYER_HEIGHT: f32 = 2.5; pub const PLAYER_CAMERA_HEIGHT: f32 = 1.0; pub const PLAYER_CROUCH_HEIGHT: f32 = 0.0; +pub const PLAYER_CROUCH_TIME_MS: u128 = 130; pub const PLAYER_LINEAR_DAMPING: f32 = 3.5; pub const PLAYER_LINEAR_DAMPING_WHILE_JUMPING: f32 = 0.25; diff --git a/src/logic/core/player/camera_player_sync.rs b/src/logic/core/player/camera_player_sync.rs index 0fd26ee..8482380 100644 --- a/src/logic/core/player/camera_player_sync.rs +++ b/src/logic/core/player/camera_player_sync.rs @@ -3,7 +3,7 @@ use bevy::{input::mouse::MouseMotion, prelude::*}; use crate::{ comps::core::{camera::MainCamera, markers::player::Player}, - constants::player_values::{PLAYER_CAMERA_HEIGHT, PLAYER_CROUCH_HEIGHT}, + constants::player_values::{PLAYER_CAMERA_HEIGHT, PLAYER_CROUCH_HEIGHT, PLAYER_CROUCH_TIME_MS}, }; use super::player_movement::PlayerLinearXZState; @@ -28,13 +28,21 @@ impl Default for MouseMovementSettings { pub fn sync_camera_to_player( mut player: Query<(&mut Transform, &PlayerLinearXZState), (With, Without)>, mut camera: Query<&mut Transform, (With, Without)>, + time: Res