Fixed falloff calculations

This commit is contained in:
Sam 2021-10-27 15:55:25 -04:00
parent 2b447852fd
commit 696da74c94

View File

@ -558,12 +558,20 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, explosion: Explosion, o
let vert_distance = let vert_distance =
(sphere_pos.z - (cyl_pos.z + half_body_height)).abs() - half_body_height; (sphere_pos.z - (cyl_pos.z + half_body_height)).abs() - half_body_height;
// Compare both checks, take whichever gives weaker effect, sets minimum of 0 so // Use whichever gives maximum distance as that closer to real value. Sets
// that explosions reach a max strength on edge of entity // minimum to 0 as negative values would indicate inside entity.
let fall_off = ((horiz_dist.max(vert_distance).max(0.0) / radius).min(1.0) - 1.0).abs(); let distance = horiz_dist.max(vert_distance).max(0.0);
// Clamp min_falloff so that it doesn't produce absurd values or NaNs
let min_falloff = min_falloff.clamp(0.0, 0.99); if distance > radius {
min_falloff + fall_off * (1.0 - min_falloff) // If further than exploion radius, no strength
0.0
} else {
// Falloff inversely proportional to radius
let fall_off = ((horiz_dist.max(vert_distance).max(0.0) / radius).min(1.0) - 1.0).abs();
// Clamp min_falloff so that it doesn't produce absurd values or NaNs
let min_falloff = min_falloff.clamp(0.0, 0.99);
min_falloff + fall_off * (1.0 - min_falloff)
}
} }
// TODO: Faster RNG? // TODO: Faster RNG?