diff options
author | Matthew Kosarek <matthew.kosarek@vention.cc> | 2021-02-17 21:06:20 -0500 |
---|---|---|
committer | Matthew Kosarek <matthew.kosarek@vention.cc> | 2021-02-17 21:06:20 -0500 |
commit | 5c409f04470e319f0a57e8791bc96cd724ee601c (patch) | |
tree | fcebe2242106d5d94eb852f90b66ab131c5655ba /frontend/_rigidbody/program_common.js | |
parent | cc6d3871008a89fcf48814596d7bfec05f2706e4 (diff) |
Proper collisions happening in 2 dimensions
Diffstat (limited to 'frontend/_rigidbody/program_common.js')
-rw-r--r-- | frontend/_rigidbody/program_common.js | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/frontend/_rigidbody/program_common.js b/frontend/_rigidbody/program_common.js index 9d097e2..988056f 100644 --- a/frontend/_rigidbody/program_common.js +++ b/frontend/_rigidbody/program_common.js @@ -36,7 +36,7 @@ function getContext(pId, pOnRun) { function requestUpdateLoop(pFunction, pOnExit) { let lDeltaTimeSeconds = undefined, - lStartTimeSeconds = undefined, + lLastTimeSeconds = undefined, lIsRunning = true; function update(pTimeStamp) { @@ -50,15 +50,18 @@ function requestUpdateLoop(pFunction, pOnExit) { pTimeStamp = pTimeStamp / 1000.0; // Convert to seconds // Time calculation - if (lStartTimeSeconds === undefined) { - lStartTimeSeconds = pTimeStamp; + if (lLastTimeSeconds === undefined) { + lLastTimeSeconds = pTimeStamp; lDeltaTimeSeconds = 0; } else { - lDeltaTimeSeconds = lStartTimeSeconds - pTimeStamp; - lStartTimeSeconds = pTimeStamp; + lDeltaTimeSeconds = pTimeStamp - lLastTimeSeconds; + lLastTimeSeconds = pTimeStamp; } - pFunction(lDeltaTimeSeconds); + while (lDeltaTimeSeconds > 0) { + pFunction(lDeltaTimeSeconds); + lDeltaTimeSeconds -= 0.16; + } requestAnimationFrame(update); } |