So, I'm getting the Y position (height) of an object in three.js then updating a greensock time variable with that. It's logging in the console but not updating the variable in greensock. What am I doing wrong? When I add a number to the time var instead of null, it works just fine, but I want to programmatically control the cubes landing speed.
Here's the relevant JS:
function flyDown(){
getFlyPosition();
TweenLite.to(cube.position , flyTime, {y: 25, ease:Sine.easeInOut} );
}
var flyTime = null;
function getFlyPosition(){
scene.updateMatrixWorld(true);
var position = new THREE.Vector3();
position.getPositionFromMatrix( cube.matrixWorld );
flyTime = Math.round(position.y/3);
console.log(flyTime);
}
Its not that it isn't working, its just that your flyTime is super high since the time is in seconds (and therefore it's falling, just super, super slowly).
I see fly time registering between 35 and 70 or so depending on circumstances. I'm not sure what your objective is but my guess is you're actually looking to divide flytime down to something at the millisecond level.
Check this out. I put .2 in as your time value and I'm getting it to "drop". It looks like all you need to do is divide flyTime or subtract it from some version of one. Again, I'm not sure what speed you're looking for.
function flyDown(){
getFlyPosition();
console.log(flyTime);
TweenLite.to(cube.position , .2, {y: 25, ease:Sine.easeInOut} );
}
var flyTime = null;
function getFlyPosition(){
scene.updateMatrixWorld(true);
var position = new THREE.Vector3();
position.getPositionFromMatrix( cube.matrixWorld );
flyTime = Math.round(position.y/3);
console.log(flyTime);
}