From 696da74c9493052b5b72f48c78b823cf494fd12e Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 27 Oct 2021 15:55:25 -0400 Subject: [PATCH] Fixed falloff calculations --- server/src/events/entity_manipulation.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 592039e7c0..8c07702ae0 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -558,12 +558,20 @@ pub fn handle_explosion(server: &Server, pos: Vec3, explosion: Explosion, o let vert_distance = (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 - // that explosions reach a max strength on edge of entity - 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) + // Use whichever gives maximum distance as that closer to real value. Sets + // minimum to 0 as negative values would indicate inside entity. + let distance = horiz_dist.max(vert_distance).max(0.0); + + if distance > radius { + // 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?