javascript - 三.JS TWEEN move object to other object speed

标签 javascript three.js move tween

我制作了一个对象 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/

相关文章:

javascript - 使用 indexedDB 存储一个 three.js 网格对象

python - 在 Pygame 1.9.4 中使用 move_ip

c++ - 在 C++ 上覆盖运算符时促进 MOVE 操作的正确方法

php - 无法重命名文件夹(PHP + Linux)

JavaScript 在页面重新加载时维护计数值

three.js - 删除 GLSL 着色器产生的莫尔图案

javascript - 如何从严格模式中获取调用者?

three.js - 如何用three.js修改UV坐标

javascript - Google Chrome 错误无法加载 google map 、ajax 调用上的 jQuery 函数

php - 如何使用 api 在 Google map 中仅显示一个国家或特定区域?