More relative motion changes

This commit is contained in:
Joshua Barretto 2021-03-12 18:53:01 +00:00 committed by Avi Weinstock
parent 5ff72a4a2e
commit 3496c356e2
4 changed files with 13 additions and 7 deletions

View File

@ -169,7 +169,7 @@ impl Body {
quadruped_low::Species::Lavadrake => 4.0,
_ => 6.0,
},
Body::Ship(_) => 0.1,
Body::Ship(_) => 0.5,
}
}

View File

@ -464,6 +464,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
@ -484,6 +486,7 @@ impl<'a> PhysicsSystemData<'a> {
Vec3::zero(),
&psdr.dt,
true,
was_on_ground,
|entity, vel| land_on_grounds.push((entity, vel)),
);
},
@ -509,6 +512,7 @@ impl<'a> PhysicsSystemData<'a> {
Vec3::zero(),
&psdr.dt,
true,
was_on_ground,
|entity, vel| land_on_grounds.push((entity, vel)),
);
},
@ -636,6 +640,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)))),
);
@ -750,6 +755,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
ground_vel: Vec3<f32>,
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;
@ -825,7 +831,6 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
> 0
}
let was_on_ground = physics_state.on_ground;
physics_state.on_ground = false;
let mut on_ground = false;
@ -948,7 +953,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 = 0.0;
vel.0.z = vel.0.z.max(0.0);
on_ground = true;
break;
} else {
@ -956,7 +961,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + 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 });
@ -992,7 +997,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + 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(

View File

@ -455,10 +455,11 @@ impl State {
for event in events {
let mut velocities = self.ecs.write_storage::<comp::Vel>();
let mut controllers = self.ecs.write_storage::<comp::Controller>();
let physics = self.ecs.read_storage::<comp::PhysicsState>();
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 } => {

View File

@ -129,7 +129,7 @@ pub fn handle_shoot(
return;
};
let vel = *dir * speed;
let vel = *dir * speed + state.ecs().read_storage::<Vel>().get(entity).map_or(Vec3::zero(), |v| v.0);
// Add an outcome
state