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 {}
}
usingPointerLock = false
velocity = 0
if (samples.length) {
const first = samples[0]
const now = performance.now()
const last = samples[samples.length - 1]
const dy = last.position - first.position
velocity = (-dy * speed) / (now - first.timestamp)
} else velocity = 0
if (Math.abs(dy) > 5) velocity = (-dy * speed) / (now - first.timestamp)
}
console.log(velocity, samples)
samples = []
startMomentum()