Reduced air resistance for better-behaving airships

This commit is contained in:
Joshua Barretto 2021-03-13 14:25:56 +00:00 committed by Avi Weinstock
parent a4e5ba0639
commit 6d8ba31e5b
3 changed files with 18 additions and 14 deletions

View File

@ -9,8 +9,8 @@ use vek::Vec2;
// Gravity is 9.81 * 4, so this makes gravity equal to .15
const GLIDE_ANTIGRAV: f32 = crate::consts::GRAVITY * 0.90;
const GLIDE_ACCEL: f32 = 12.0;
const GLIDE_SPEED: f32 = 45.0;
const GLIDE_ACCEL: f32 = 8.0;
const GLIDE_SPEED: f32 = 16.0;
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct Data;

View File

@ -17,8 +17,8 @@ use std::time::Duration;
use vek::*;
pub const MOVEMENT_THRESHOLD_VEL: f32 = 3.0;
const BASE_HUMANOID_AIR_ACCEL: f32 = 8.0;
const BASE_FLIGHT_ACCEL: f32 = 16.0;
const BASE_HUMANOID_AIR_ACCEL: f32 = 0.5;
const BASE_FLIGHT_ACCEL: f32 = 3.5;
const BASE_HUMANOID_WATER_ACCEL: f32 = 150.0;
const BASE_HUMANOID_WATER_SPEED: f32 = 180.0;
// const BASE_HUMANOID_CLIMB_ACCEL: f32 = 10.0;
@ -310,7 +310,10 @@ fn swim_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32, depth:
fn fly_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) {
// Update velocity (counteract gravity with lift)
// TODO: Do this better
update.vel.0 += Vec3::unit_z() * data.dt.0 * GRAVITY
// A loss factor is needed to counteract the very slight deviation in gravity
// due to precision issues
const LOSS_FACTOR: f32 = 0.995;
update.vel.0 += Vec3::unit_z() * data.dt.0 * GRAVITY * LOSS_FACTOR
+ Vec3::new(
data.inputs.move_dir.x,
data.inputs.move_dir.y,

View File

@ -30,7 +30,7 @@ pub const BOUYANCY: f32 = 1.0;
// friction is 0.01, and the speed is 1.0, then after 1/60th of a second the
// speed will be 0.99. after 1 second the speed will be 0.54, which is 0.99 ^
// 60.
pub const FRIC_AIR: f32 = 0.0125;
pub const FRIC_AIR: f32 = 0.0025;
pub const FRIC_FLUID: f32 = 0.4;
// Integrates forces, calculates the new velocity based off of the old velocity
@ -415,7 +415,7 @@ impl<'a> PhysicsData<'a> {
let mut pos = *pos;
let mut vel = *vel;
if sticky.is_some() && physics_state.on_surface().is_some() {
vel.0 = Vec3::zero();
vel.0 = physics_state.ground_vel;
return (pos_writes, vel_writes, land_on_grounds);
}
@ -977,7 +977,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
{
// ...block-hop!
pos.0.z = (pos.0.z + 0.1).floor() + block_height;
vel.0.z = vel.0.z.max(0.0);
vel.0.z = 0.0;
on_ground = true;
break;
} else {
@ -1019,7 +1019,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
near_iter.clone(),
radius,
z_range.clone(),
) && vel.0.z < 0.1
) && vel.0.z < 0.25
&& vel.0.z > -1.5
// && was_on_ground
// && !collision_with(
@ -1037,15 +1037,11 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
.filter(|block| block.is_solid())
.map(|block| block.solid_height())
.unwrap_or(0.0);
vel.0.z = 0.0;
pos.0.z = (pos.0.z - 0.1).floor() + snap_height;
physics_state.on_ground = true;
}
if physics_state.on_ground {
vel.0 *= (1.0 - FRIC_GROUND.min(1.0)).powf(dt.0 * 60.0);
physics_state.ground_vel = ground_vel;
}
let dirs = [
Vec3::unit_x(),
Vec3::unit_y(),
@ -1072,6 +1068,11 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
physics_state.on_wall = None;
}
if physics_state.on_ground || physics_state.on_wall.is_some() {
vel.0 *= (1.0 - FRIC_GROUND.min(1.0)).powf(dt.0 * 60.0);
physics_state.ground_vel = ground_vel;
}
// Figure out if we're in water
physics_state.in_liquid = collision_iter(
pos.0,