Three.JS TWEEN 将对象移动到其他对象的速度

Three.JS TWEEN move object to other object speed

我制作了一个对象移动到其他对象的游戏。

new TWEEN.Tween( object.position ).to({
   x: Math.position = pointX,
   z: Math.position.z = pointZ
}).easing( TWEEN.Easing.Linear.None).start();

问题是物体以不同的速度移动到每个点,因为点的位置不同。

我怎样才能使我的物体到点的速度始终相同?

一般来说,它会是这样的:

var speed = 5; // units a second, the speed we want
var currentPoint = new THREE.Vector3();  // we will re-use it


// this part is in a function of event listener of, for example, a button
currentPoint.copy(cube.position); // cube is the object to move
var distance = currentPoint.distanceTo(destinationPoint.position)
var duration = (distance / speed) * 1000; // in milliseconds
new TWEEN.Tween(cube.position)
  .to(destinationPoint.position, duration) // destinationPoint is the object of destination
  .start();

jsfiddle 例子。看看 tweening() 函数。