Guard to prevent warm-up animation from overshooting start position when dropping frames

This commit is contained in:
Diego Marcos
2018-10-26 10:50:03 -07:00
parent 2b8dee29ef
commit ea7bb841a0
2 changed files with 15 additions and 6 deletions

View File

@@ -121,14 +121,18 @@ AFRAME.registerComponent('beat', {
} else {
// Only check collisions when close.
const collisionZThreshold = -4;
if (position.z > collisionZThreshold) { this.checkCollisions(); }
// Move.
if (position.z < this.startPositionZ) {
let newPositionZ = position.z + BEAT_WARMUP_SPEED * (timeDelta / 1000);
// Warm up / warp in.
position.z += BEAT_WARMUP_SPEED * (timeDelta / 1000);
if (position.z >= this.startPositionZ) {
if (newPositionZ < this.startPositionZ) {
this.beams.newBeam(this.data.color, position);
position.z = newPositionZ;
} else {
position.z = this.startPositionZ;
}
} else {
// Standard moving.