diff --git a/engine/inc/uf/utils/math/physics/structs.h b/engine/inc/uf/utils/math/physics/structs.h index 21dd8688..ef26a35a 100644 --- a/engine/inc/uf/utils/math/physics/structs.h +++ b/engine/inc/uf/utils/math/physics/structs.h @@ -469,6 +469,7 @@ namespace pod { uf::stl::vector bodies; uf::stl::vector constraints; + float timeAccumulator = 0.0f; pod::Vector3f gravity = { 0, -9.81f, 0 }; pod::BVH dynamicBvh; pod::BVH staticBvh; diff --git a/engine/src/utils/math/physics/impl.cpp b/engine/src/utils/math/physics/impl.cpp index b55635f1..6fcfc9dd 100644 --- a/engine/src/utils/math/physics/impl.cpp +++ b/engine/src/utils/math/physics/impl.cpp @@ -68,17 +68,13 @@ void uf::physics::tick( pod::World& world, float dt ) { return; } - UF_PHYSICS_TIMER_MULTITRACE_START("Tick Step Begin"); - static float accumulator = 0; - accumulator += dt; - float timestep = uf::physics::settings.timestep; - - while ( accumulator >= timestep ) { + world.timeAccumulator += dt; + while ( world.timeAccumulator >= timestep ) { if ( uf::physics::settings.substeps > 0 ) uf::physics::substep( world, timestep, uf::physics::settings.substeps ); else uf::physics::step( world, timestep ); - accumulator -= timestep; + world.timeAccumulator -= timestep; UF_PHYSICS_TIMER_MULTITRACE("Tick Accumulation Step"); } UF_PHYSICS_TIMER_MULTITRACE_END("Tick Step Complete");