From d793817170e59accb2b2df31dcc8ceffef0c68b8 Mon Sep 17 00:00:00 2001 From: hexagonhexagon Date: Sun, 14 Jun 2020 19:00:38 -0400 Subject: [PATCH 1/2] The camera will not have extra velocity when the camera is held still. --- src/js/game/camera.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/js/game/camera.js b/src/js/game/camera.js index 709f3ac7..65f87669 100644 --- a/src/js/game/camera.js +++ b/src/js/game/camera.js @@ -28,6 +28,7 @@ const velocitySmoothing = 0.5; const velocityFade = 0.98; const velocityStrength = 0.4; const velocityMax = 20; +const ticksBeforeErasingVelocity = 2; /** * @enum {string} @@ -58,6 +59,8 @@ export class Camera extends BasicSerializableObject { // Input handling this.currentlyMoving = false; this.lastMovingPosition = null; + this.lastMovingPositionLastTick = null; + this.numTicksStandingStill = null; this.cameraUpdateTimeBucket = 0.0; this.didMoveSinceTouchStart = false; this.currentlyPinching = false; @@ -667,6 +670,8 @@ export class Camera extends BasicSerializableObject { this.touchPostMoveVelocity = new Vector(0, 0); this.currentlyMoving = true; this.lastMovingPosition = pos; + this.lastMovingPositionLastTick = null; + this.numTicksStandingStill = 0; this.didMoveSinceTouchStart = false; } @@ -716,6 +721,8 @@ export class Camera extends BasicSerializableObject { this.currentlyMoving = false; this.currentlyPinching = false; this.lastMovingPosition = null; + this.lastMovingPositionLastTick = null; + this.numTicksStandingStill = null; this.lastPinchPositions = null; this.userInteraction.dispatch(USER_INTERACT_TOUCHEND); this.didMoveSinceTouchStart = false; @@ -813,6 +820,20 @@ export class Camera extends BasicSerializableObject { this.touchPostMoveVelocity = this.touchPostMoveVelocity.multiplyScalar(velocityFade); + // Check if the camera is being dragged but standing still: if not, zero out `touchPostMoveVelocity`. + if (this.currentlyMoving && this.desiredCenter === null) { + if (this.lastMovingPositionLastTick === this.lastMovingPosition) { + this.numTicksStandingStill += 1; + } else { + this.numTicksStandingStill = 0; + } + this.lastMovingPositionLastTick = this.lastMovingPosition; + + if (this.numTicksStandingStill >= ticksBeforeErasingVelocity) { + this.touchPostMoveVelocity.x = 0; + this.touchPostMoveVelocity.y = 0; + } + } // Check influence of past points if (!this.currentlyMoving && !this.currentlyPinching) { const len = this.touchPostMoveVelocity.length(); From 46a5bdb76cf50ccacf6ee31ee33f6e510fbf43e0 Mon Sep 17 00:00:00 2001 From: hexagonhexagon Date: Mon, 22 Jun 2020 02:19:52 -0400 Subject: [PATCH 2/2] Make changes requested by tobspr. --- src/js/game/camera.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/js/game/camera.js b/src/js/game/camera.js index 65f87669..0364f695 100644 --- a/src/js/game/camera.js +++ b/src/js/game/camera.js @@ -722,7 +722,7 @@ export class Camera extends BasicSerializableObject { this.currentlyPinching = false; this.lastMovingPosition = null; this.lastMovingPositionLastTick = null; - this.numTicksStandingStill = null; + this.numTicksStandingStill = 0; this.lastPinchPositions = null; this.userInteraction.dispatch(USER_INTERACT_TOUCHEND); this.didMoveSinceTouchStart = false; @@ -822,12 +822,15 @@ export class Camera extends BasicSerializableObject { // Check if the camera is being dragged but standing still: if not, zero out `touchPostMoveVelocity`. if (this.currentlyMoving && this.desiredCenter === null) { - if (this.lastMovingPositionLastTick === this.lastMovingPosition) { - this.numTicksStandingStill += 1; + if ( + this.lastMovingPositionLastTick !== null && + this.lastMovingPositionLastTick.equalsEpsilon(this.lastMovingPosition) + ) { + this.numTicksStandingStill++; } else { this.numTicksStandingStill = 0; } - this.lastMovingPositionLastTick = this.lastMovingPosition; + this.lastMovingPositionLastTick = this.lastMovingPosition.copy(); if (this.numTicksStandingStill >= ticksBeforeErasingVelocity) { this.touchPostMoveVelocity.x = 0;