From 21656706f6eb87796d1bd0b4148434045acd29c3 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Mon, 15 Mar 2021 00:23:06 +0000 Subject: [PATCH] Improved climbing, block-hopping on airships --- common/src/states/climb.rs | 31 ++++++------------------------- common/sys/src/phys.rs | 13 ++++++------- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/common/src/states/climb.rs b/common/src/states/climb.rs index cb97013ca9..040c31ac20 100644 --- a/common/src/states/climb.rs +++ b/common/src/states/climb.rs @@ -9,12 +9,9 @@ use crate::{ util::Dir, }; use serde::{Deserialize, Serialize}; -use vek::{ - vec::{Vec2, Vec3}, - Lerp, -}; +use vek::*; -const HUMANOID_CLIMB_ACCEL: f32 = 5.0; +const HUMANOID_CLIMB_ACCEL: f32 = 24.0; const CLIMB_SPEED: f32 = 5.0; #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] @@ -76,26 +73,10 @@ impl CharacterBehavior for Data { }; // Apply Vertical Climbing Movement - if update.vel.0.z <= CLIMB_SPEED { - match climb { - Climb::Down => { - update.vel.0 -= - data.dt.0 * update.vel.0.map(|e| e.abs().powf(1.5) * e.signum() * 1.0); - }, - Climb::Up => { - update.vel.0.z = (update.vel.0.z + data.dt.0 * GRAVITY * 1.25).min(CLIMB_SPEED); - }, - Climb::Hold => { - // Antigrav - update.vel.0.z = - (update.vel.0.z + data.dt.0 * GRAVITY * 1.075).min(CLIMB_SPEED); - update.vel.0 = Lerp::lerp( - update.vel.0, - Vec3::zero(), - 30.0 * data.dt.0 / (1.0 - update.vel.0.z.min(0.0) * 5.0), - ); - }, - } + match climb { + Climb::Down => update.vel.0.z += data.dt.0 * (GRAVITY - HUMANOID_CLIMB_ACCEL), + Climb::Up => update.vel.0.z += data.dt.0 * (GRAVITY + HUMANOID_CLIMB_ACCEL), + Climb::Hold => update.vel.0.z += data.dt.0 * GRAVITY, } update diff --git a/common/sys/src/phys.rs b/common/sys/src/phys.rs index e9961be469..95b6944ff4 100644 --- a/common/sys/src/phys.rs +++ b/common/sys/src/phys.rs @@ -1039,13 +1039,12 @@ fn cylinder_voxel_collision<'a, T: BaseVol + ReadVol>( // ...and we're being pushed out horizontally... && resolve_dir.z == 0.0 // ...and the vertical resolution direction is sufficiently great... - && -dir.z > 0.1 - && was_on_ground - // // ...and we're falling/standing OR there is a block *directly* beneath our current origin (note: not hitbox)... - // && (vel.0.z <= 0.0 || terrain + && dir.z < -0.1 + // ...and we're falling/standing OR there is a block *directly* beneath our current origin (note: not hitbox)... + // && terrain // .get((pos.0 - Vec3::unit_z() * 0.1).map(|e| e.floor() as i32)) // .map(|block| block.is_solid()) - // .unwrap_or(false)) + // .unwrap_or(false) // ...and there is a collision with a block beneath our current hitbox... && collision_with( pos.0 + resolve_dir - Vec3::unit_z() * 1.25, @@ -1129,8 +1128,8 @@ fn cylinder_voxel_collision<'a, T: BaseVol + ReadVol>( &terrain, block_true, near_iter.clone(), - radius + 0.05, - z_range.start - 0.05..z_range.end + 0.05, + radius, + z_range.clone(), ) { (a + dir, true) } else {