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

时间:2015-08-13 19:47:30

标签: javascript three.js gsap

所以,我在three.js中得到一个对象的Y位置(高度),然后用它更新一个绿色时间变量。它在控制台中登录但没有更新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);
  }

1 个答案:

答案 0 :(得分:1)

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

根据具体情况,我看到飞行时间在35到70之间。我不确定你的目标是什么,但我猜你实际上是想把飞行时间分成毫秒级的东西。

检查一下。我把.2作为你的时间价值,我让它“掉落”。看起来你需要做的就是除了flyTime或从某个版本中减去它。再说一次,我不确定你要找的速度。

  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