From 6add95bd5c955a0ef3b26d60d47f05ee13181e30 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 14 Mar 2021 23:07:32 +0000 Subject: [PATCH] Fixed block-snapping, climbing and airship takeoff --- common/src/states/utils.rs | 2 +- common/sys/src/phys.rs | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 019e9b21fa..545232fa20 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -197,7 +197,7 @@ pub fn handle_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) { if let Some(depth) = data.physics.in_liquid { swim_move(data, update, efficiency, depth); } else if input_is_pressed(data, InputKind::Fly) - && !data.physics.on_ground + && (!data.physics.on_ground || data.body.jump_impulse().is_none()) && data.body.can_fly().is_some() { fly_move(data, update, efficiency * data.body.can_fly().expect("can_fly is_some right above this")); diff --git a/common/sys/src/phys.rs b/common/sys/src/phys.rs index e5577546ec..7a55857de3 100644 --- a/common/sys/src/phys.rs +++ b/common/sys/src/phys.rs @@ -1049,14 +1049,14 @@ fn cylinder_voxel_collision<'a, T: BaseVol + ReadVol>( { // ...block-hop! pos.0.z = (pos.0.z + 0.1).floor() + block_height; - vel.0.z = 0.0; + vel.0.z = vel.0.z.max(0.0); on_ground = true; break; } else { // Correct the velocity vel.0 = vel.0.map2(resolve_dir, |e, d| { if d * e.signum() < 0.0 { - if d < 0.0 { d.max(0.0) } else { d.min(0.0) } + if d < 0.0 { d.min(0.0) } else { d.max(0.0) } } else { e } @@ -1093,6 +1093,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol + ReadVol>( z_range.clone(), ) && vel.0.z < 0.25 && vel.0.z > -1.5 + && was_on_ground && block_snap { let snap_height = terrain @@ -1119,8 +1120,8 @@ fn cylinder_voxel_collision<'a, T: BaseVol + ReadVol>( &terrain, block_true, near_iter.clone(), - radius, - z_range.clone(), + radius + 0.05, + z_range.start - 0.05..z_range.end + 0.05, ) { (a + dir, true) } else { @@ -1133,9 +1134,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol + ReadVol>( } if physics_state.on_ground || physics_state.on_wall.is_some() { - if physics_state.on_ground { - vel.0 *= (1.0 - FRIC_GROUND.min(1.0)).powf(dt.0 * 60.0); - } + vel.0 *= (1.0 - FRIC_GROUND.min(1.0)).powf(dt.0 * 60.0); physics_state.ground_vel = ground_vel; }