From 33920f31ac5fe2ffcfe81c9ee2f33c275abbe753 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 12 Mar 2021 18:53:01 +0000 Subject: [PATCH] More relative motion changes --- common/src/states/utils.rs | 2 +- common/sys/src/phys.rs | 13 +++++++++---- common/sys/src/state.rs | 3 ++- server/src/events/entity_creation.rs | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 7969f25914..d86731a6bf 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -164,7 +164,7 @@ impl Body { quadruped_low::Species::Lavadrake => 4.0, _ => 6.0, }, - Body::Ship(_) => 0.1, + Body::Ship(_) => 0.5, } } diff --git a/common/sys/src/phys.rs b/common/sys/src/phys.rs index 717713dd9b..6e18eb0d43 100644 --- a/common/sys/src/phys.rs +++ b/common/sys/src/phys.rs @@ -453,6 +453,8 @@ impl<'a> PhysicsSystemData<'a> { Vec3::zero() }; + let was_on_ground = physics_state.on_ground; + match &*collider { Collider::Voxel { .. } => { // for now, treat entities with voxel colliders as their bounding @@ -473,6 +475,7 @@ impl<'a> PhysicsSystemData<'a> { Vec3::zero(), &psdr.dt, true, + was_on_ground, |entity, vel| land_on_grounds.push((entity, vel)), ); }, @@ -498,6 +501,7 @@ impl<'a> PhysicsSystemData<'a> { Vec3::zero(), &psdr.dt, true, + was_on_ground, |entity, vel| land_on_grounds.push((entity, vel)), ); }, @@ -625,6 +629,7 @@ impl<'a> PhysicsSystemData<'a> { transform_to.mul_direction(vel_other.0), &psdr.dt, false, + was_on_ground, |entity, vel| land_on_grounds.push((entity, Vel(transform_from.mul_direction(vel.0)))), ); @@ -739,6 +744,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol + ReadVol>( ground_vel: Vec3, dt: &DeltaTime, apply_velocity_step: bool, // Stupid hack + was_on_ground: bool, mut land_on_ground: impl FnMut(Entity, Vel), ) { let (radius, z_min, z_max) = cylinder; @@ -814,7 +820,6 @@ fn cylinder_voxel_collision<'a, T: BaseVol + ReadVol>( > 0 } - let was_on_ground = physics_state.on_ground; physics_state.on_ground = false; let mut on_ground = false; @@ -937,7 +942,7 @@ 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 { @@ -945,7 +950,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol + ReadVol>( vel.0 = vel.0.map2( resolve_dir, |e, d| { - if d * e.signum() < 0.0 { 0.0 } else { e } + if d * e.signum() < 0.0 { if d < 0.0 { d.max(0.0) } else { d.min(0.0) } } else { e } }, ); pos_delta *= resolve_dir.map(|e| if e != 0.0 { 0.0 } else { 1.0 }); @@ -981,7 +986,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol + ReadVol>( near_iter.clone(), radius, z_range.clone(), - ) && vel.0.z < 0.0 + ) && vel.0.z < 0.01 && vel.0.z > -1.5 && was_on_ground && !collision_with( diff --git a/common/sys/src/state.rs b/common/sys/src/state.rs index bc256766c5..788d812cf8 100644 --- a/common/sys/src/state.rs +++ b/common/sys/src/state.rs @@ -455,10 +455,11 @@ impl State { for event in events { let mut velocities = self.ecs.write_storage::(); let mut controllers = self.ecs.write_storage::(); + let physics = self.ecs.read_storage::(); match event { LocalEvent::Jump(entity) => { if let Some(vel) = velocities.get_mut(entity) { - vel.0.z = HUMANOID_JUMP_ACCEL; + vel.0.z = HUMANOID_JUMP_ACCEL + physics.get(entity).map_or(0.0, |ps| ps.ground_vel.z); } }, LocalEvent::ApplyImpulse { entity, impulse } => { diff --git a/server/src/events/entity_creation.rs b/server/src/events/entity_creation.rs index 2fb80f0bd9..ac0432482e 100644 --- a/server/src/events/entity_creation.rs +++ b/server/src/events/entity_creation.rs @@ -130,7 +130,7 @@ pub fn handle_shoot( return; }; - let vel = *dir * speed; + let vel = *dir * speed + state.ecs().read_storage::().get(entity).map_or(Vec3::zero(), |v| v.0); // Add an outcome state