时间变量未在 gsap 代码中更新

Time variable not updating in gsap code

所以,我在 three.js 中获取对象的 Y 位置(高度),然后用它更新 greensock 时间变量。它正在登录控制台但不更新 greensock 中的变量。我究竟做错了什么?当我向时间 var 添加一个数字而不是 null 时,它工作得很好,但我想以编程方式控制立方体着陆速度。

Here's a plunker

这是相关的 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);
  }

不是它不起作用,只是你的 flyTime 非常高,因为时间以秒为单位(因此它正在下降,只是非常非常慢)。

我看到飞行时间在 35 到 70 之间,具体取决于具体情况。我不确定你的 objective 是什么,但我猜你实际上是想将飞行时间划分为毫秒级别的东西。

看看这个。我把 .2 作为你的时间值,我把它变成了 "drop"。看起来您需要做的就是划分 flyTime 或从某个版本的 one 中减去它。同样,我不确定您要寻找的速度。

  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);
  }

http://plnkr.co/edit/MEXRiovDI2RMPaUKza4e?p=preview