Skip to content

Instantly share code, notes, and snippets.

@kmagiera
Last active October 25, 2018 10:14
Show Gist options
  • Save kmagiera/95df57cf989fa60534c5081b56525b59 to your computer and use it in GitHub Desktop.
Save kmagiera/95df57cf989fa60534c5081b56525b59 to your computer and use it in GitHub Desktop.
const EPS = 1e-3;
const EMPTY_FRAMES_THRESHOLDS = 5;
function stopWhenNeeded(dt, position, velocity, clock) {
const ds = diff(position);
const noMovementFrames = new Value(0);
return cond(
lessThan(abs(ds), EPS),
[
set(noMovementFrames, add(noMovementFrames, 1)),
cond(
greaterThan(noMovementFrames, EMPTY_FRAMES_THRESHOLDS),
stopClock(clock)
),
],
set(noMovementFrames, 0)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment