Stop momentum if slow enough.

This commit is contained in:
Leo Vasanko 2025-08-25 17:09:36 -06:00
parent b07c0808ab
commit 2f69e7bd88

View File

@ -96,13 +96,14 @@ function createMomentumDrag({
} catch {} } catch {}
} }
usingPointerLock = false usingPointerLock = false
velocity = 0
if (samples.length) { if (samples.length) {
const first = samples[0] const first = samples[0]
const now = performance.now() const now = performance.now()
const last = samples[samples.length - 1] const last = samples[samples.length - 1]
const dy = last.position - first.position const dy = last.position - first.position
velocity = (-dy * speed) / (now - first.timestamp) if (Math.abs(dy) > 5) velocity = (-dy * speed) / (now - first.timestamp)
} else velocity = 0 }
console.log(velocity, samples) console.log(velocity, samples)
samples = [] samples = []
startMomentum() startMomentum()