From 01ac937db57d7a4347f5c3daa283e326a8354fe1 Mon Sep 17 00:00:00 2001 From: Joseph Gerardot Date: Sun, 19 Jan 2020 14:44:44 -0500 Subject: [PATCH] Fixup energy regen math to properly account for acceleration at any framerate. --- common/src/sys/stats.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/src/sys/stats.rs b/common/src/sys/stats.rs index ad5e16e984..6f059dbe42 100644 --- a/common/src/sys/stats.rs +++ b/common/src/sys/stats.rs @@ -5,7 +5,7 @@ use crate::{ }; use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; -const ENERGY_REGEN_ACCEL: f32 = 0.5; +const ENERGY_REGEN_ACCEL: f32 = 20.0; /// This system kills players, levels them up, and regenerates energy. pub struct Sys; @@ -80,8 +80,9 @@ impl<'a> System<'a> for Sys { energy.current() < energy.maximum() } { let mut energy = energy.get_mut_unchecked(); + // Have to account for Calc I differential equations due to acceleration + energy.change_by((energy.regen_rate * dt.0 + ENERGY_REGEN_ACCEL * dt.0.powf(2.0) / 2.0) as i32, EnergySource::Regen); energy.regen_rate += ENERGY_REGEN_ACCEL * dt.0; - energy.change_by(energy.regen_rate as i32, EnergySource::Regen); } } // All other states do not regen and set the rate back to zero.