我制作了一个对象 move 到其他对象的游戏。
new TWEEN.Tween( object.position ).to({
x: Math.position = pointX,
z: Math.position.z = pointZ
}).easing( TWEEN.Easing.Linear.None).start();
问题是物体以不同的速度 move 到每个点,因为点的位置不同。
如何使我的物体到点的速度始终相同?
最佳答案
一般来说,它看起来像这样:
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()
函数。
关于javascript - 三.JS TWEEN move object to other object speed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42145768/