More relative motion changes

This commit is contained in:
Joshua Barretto 2021-03-12 18:53:01 +00:00
parent 0b954f8db8
commit 33920f31ac
4 changed files with 13 additions and 7 deletions

View File

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

View File

@ -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<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;
@ -814,7 +820,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;
@ -937,7 +942,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 {
@ -945,7 +950,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 });
@ -981,7 +986,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

@ -130,7 +130,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