From aeb37a1f33928a5a18102272f1514f6f368defbd Mon Sep 17 00:00:00 2001 From: timokoesters Date: Mon, 3 Feb 2020 20:43:36 +0100 Subject: [PATCH] improvement: char speed --- common/src/states/climb.rs | 10 ++-------- common/src/states/utils.rs | 27 +++++++++++++++------------ common/src/sys/phys.rs | 2 +- voxygen/src/anim/character/run.rs | 2 +- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/common/src/states/climb.rs b/common/src/states/climb.rs index 08fe2742a6..a105a30323 100644 --- a/common/src/states/climb.rs +++ b/common/src/states/climb.rs @@ -27,19 +27,13 @@ impl StateHandler for State { }; // If no wall is in front of character ... - if let None = ecs_data.physics.on_wall { + if ecs_data.physics.on_wall.is_none() || ecs_data.physics.on_ground { if ecs_data.inputs.jump.is_pressed() { // They've climbed atop something, give them a boost //TODO: JUMP EVENT - } else { - // Just fall off - update.character = CharacterState::Idle(None); } - } - - // Remove climb state on ground, otherwise character will get stuck - if ecs_data.physics.on_ground { update.character = CharacterState::Idle(None); + return update; } // Move player diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index c0854f9d79..1f9c3b5e0b 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -6,23 +6,24 @@ use vek::vec::{Vec2, Vec3}; pub fn handle_move_dir(ecs_data: &EcsStateData, update: &mut StateUpdate) { let (accel, speed): (f32, f32) = if ecs_data.physics.on_ground { - let accel = 50.0; - let speed = 120.0; + let accel = 100.0; + let speed = 8.0; (accel, speed) } else { - let accel = 10.0; - let speed = 100.0; + let accel = 100.0; + let speed = 8.0; (accel, speed) }; // Move player according to move_dir - update.vel.0 += Vec2::broadcast(ecs_data.dt.0) - * ecs_data.inputs.move_dir - * if update.vel.0.magnitude_squared() < speed.powf(2.0) { - accel - } else { - 0.0 - }; + if update.vel.0.magnitude_squared() < speed.powf(2.0) { + update.vel.0 = + update.vel.0 + Vec2::broadcast(ecs_data.dt.0) * ecs_data.inputs.move_dir * accel; + let mag2 = update.vel.0.magnitude_squared(); + if mag2 > speed.powf(2.0) { + update.vel.0 = update.vel.0.normalized() * speed; + } + } // Set direction based on move direction let ori_dir = if update.character.is_attack() || update.character.is_block() { @@ -56,8 +57,10 @@ pub fn handle_sit(ecs_data: &EcsStateData, update: &mut StateUpdate) { } pub fn handle_climb(ecs_data: &EcsStateData, update: &mut StateUpdate) { - if (ecs_data.inputs.climb.is_pressed() || ecs_data.inputs.climb_down.is_pressed()) + if (ecs_data.inputs.climb.is_just_pressed() || ecs_data.inputs.climb_down.is_pressed()) && ecs_data.physics.on_wall.is_some() + && !ecs_data.physics.on_ground + //&& update.vel.0.z < 0.0 && ecs_data.body.is_humanoid() { update.character = CharacterState::Climb(None); diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index 955d229c22..1a72708302 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -11,7 +11,7 @@ use { vek::*, }; -pub const GRAVITY: f32 = 9.81 * 4.0; +pub const GRAVITY: f32 = 9.81 * 7.0; const BOUYANCY: f32 = 0.0; // Friction values used for linear damping. They are unitless quantities. The // value of these quantities must be between zero and one. They represent the diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index f70fbbb5ec..26565dfb78 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -27,7 +27,7 @@ impl Animation for RunAnimation { let constant = 1.0; let wave = (((5.0) - / (1.1 + 3.9 * ((anim_time as f32 * constant as f32 * 1.2).sin()).powf(2.0 as f32))) + / (1.1 + 3.9 * ((anim_time as f32 * constant as f32 * 4.2).sin()).powf(2.0 as f32))) .sqrt()) * ((anim_time as f32 * constant as f32 * 1.2).sin()); let wave_cos = (((5.0)