Created
August 31, 2015 14:16
-
-
Save captDaylight/b6b907a919892720545d to your computer and use it in GitHub Desktop.
Simple Tween
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tween(finalPos, prevPos, tweenRatio) { | |
if (finalPos === prevPos) { | |
return prevPos; | |
} else { | |
let dist = Math.abs(finalPos - prevPos); | |
if (dist < 0.005) { | |
// set to final position when getting close | |
return prevPos; | |
} else { | |
// tween | |
let approach = dist * tweenRatio; | |
if (prevPos < finalPos) | |
return prevPos + approach; | |
else | |
return prevPos - approach; | |
} | |
} | |
}; | |
module.exports = tween; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using this in my threejs animation cycle like so: