2017-02-09 109 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