Improved climbing, block-hopping on airships

This commit is contained in:
Joshua Barretto 2021-03-15 00:23:06 +00:00 committed by Avi Weinstock
parent 546ee48073
commit 1e9ee3d243
2 changed files with 12 additions and 32 deletions

View File

@ -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

View File

@ -1039,13 +1039,12 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + 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<Vox = Block> + 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 {