diff --git a/src/config.rs b/src/config.rs index cffbcbb..626b8e9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,11 +21,16 @@ pub const MARGIN_BELLOW: f32 = 400.0; // Player pub const PLAYER_HITBOX: Vec2 = Vec2::new(20.0, 40.0); pub const FALL_SPEED: f32 = 500.0; -pub const DIVE_SPEED: f32 = 2700.0; -pub const HORIZONTAL_SPEED: f32 = 450.0; +pub const DIVE_SPEED: f32 = 2000.0; +pub const HORIZONTAL_SPEED: f32 = 400.0; pub const START_POSITION: Vec3 = Vec3::new(0.0, 0.0, 2.0); pub const CAMERAE_OFFSET: f32 = 280.0; +// Movement intertia +pub const HORIZONTAL_ACCEL: f32 = 2600.0; +pub const HORIZONTAL_FRICTION: f32 = 1800.0; +pub const VERTICAL_RATE: f32 = 4000.0; + // Validator pub const INERTIA_MARGIN: f32 = 4.0; pub const DESIGN_LATERAL_SPEED_RATIO: f32 = 0.6; diff --git a/src/gameplay/player.rs b/src/gameplay/player.rs index 6c4e5a0..1a51429 100644 --- a/src/gameplay/player.rs +++ b/src/gameplay/player.rs @@ -2,9 +2,12 @@ use bevy::prelude::*; use crate::config::DIVE_SPEED; use crate::config::FALL_SPEED; +use crate::config::HORIZONTAL_ACCEL; +use crate::config::HORIZONTAL_FRICTION; use crate::config::HORIZONTAL_SPEED; use crate::config::PLAYER_HITBOX; use crate::config::START_POSITION; +use crate::config::VERTICAL_RATE; use crate::gameplay::collision::Collider; use crate::gameplay::collision::check_collision_with_player; use crate::states::GameState; @@ -34,9 +37,43 @@ fn spawn_player(mut commands: Commands) { )); } +// Move value to target by max_step +fn approach(value: f32, target: f32, max_step: f32) -> f32 { + if value < target { + (value + max_step).min(target) + } else { + (value - max_step).max(target) + } +} + +// For debug +#[derive(Resource)] +pub struct MoveSettings { + pub horizontal_speed: f32, + pub horizontal_accel: f32, + pub horizontal_friction: f32, + pub fall_speed: f32, + pub dive_speed: f32, + pub vertical_rate: f32, +} + +impl Default for MoveSettings { + fn default() -> Self { + Self { + horizontal_speed: HORIZONTAL_SPEED, + horizontal_accel: HORIZONTAL_ACCEL, + horizontal_friction: HORIZONTAL_FRICTION, + fall_speed: FALL_SPEED, + dive_speed: DIVE_SPEED, + vertical_rate: VERTICAL_RATE, + } + } +} + // Input + movement system for the player pub(crate) fn move_player( input: Res>, + settings: Res, time: Res