2017-02-09 131 views
1

我制作了一个物体移动到其他物体的游戏。Three.JS TWEEN将物体移动到其他物体速度

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

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

我怎样才能使我的对象的速度始终相同?

+1

你知道距离,你有期望的速度,所以时间就是距离/速度。您在哪里以及如何设置补间的时间? – prisoner849

+2

持续时间是tween.to的第二个参数(对象,持续时间) – Radio

回答

2

一般情况下,它看起来就像这样:

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()函数。

+0

感谢您的帮助 –

+1

不客气) – prisoner849