Fixed block-snapping, climbing and airship takeoff

This commit is contained in:
Joshua Barretto
2021-03-14 23:07:32 +00:00
committed by Avi Weinstock
parent 23b1417275
commit 6add95bd5c
2 changed files with 7 additions and 8 deletions

View File

@ -197,7 +197,7 @@ pub fn handle_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) {
if let Some(depth) = data.physics.in_liquid { if let Some(depth) = data.physics.in_liquid {
swim_move(data, update, efficiency, depth); swim_move(data, update, efficiency, depth);
} else if input_is_pressed(data, InputKind::Fly) } 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() && data.body.can_fly().is_some()
{ {
fly_move(data, update, efficiency * data.body.can_fly().expect("can_fly is_some right above this")); fly_move(data, update, efficiency * data.body.can_fly().expect("can_fly is_some right above this"));

View File

@ -1049,14 +1049,14 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
{ {
// ...block-hop! // ...block-hop!
pos.0.z = (pos.0.z + 0.1).floor() + block_height; 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; on_ground = true;
break; break;
} else { } else {
// Correct the velocity // Correct the velocity
vel.0 = vel.0.map2(resolve_dir, |e, d| { vel.0 = vel.0.map2(resolve_dir, |e, d| {
if d * e.signum() < 0.0 { 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 { } else {
e e
} }
@ -1093,6 +1093,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
z_range.clone(), z_range.clone(),
) && vel.0.z < 0.25 ) && vel.0.z < 0.25
&& vel.0.z > -1.5 && vel.0.z > -1.5
&& was_on_ground
&& block_snap && block_snap
{ {
let snap_height = terrain let snap_height = terrain
@ -1119,8 +1120,8 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
&terrain, &terrain,
block_true, block_true,
near_iter.clone(), near_iter.clone(),
radius, radius + 0.05,
z_range.clone(), z_range.start - 0.05..z_range.end + 0.05,
) { ) {
(a + dir, true) (a + dir, true)
} else { } else {
@ -1133,9 +1134,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
} }
if physics_state.on_ground || physics_state.on_wall.is_some() { 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; physics_state.ground_vel = ground_vel;
} }