2017-02-09 17 views
1

개체를 다른 개체로 이동하는 게임을 만듭니다.Three.JS TWEEN 개체를 다른 개체 속도로 이동

포인트의 위치가 다르기 때문에 객체가 각 포인트로 다른 속도로 이동한다는 것이 문제입니다.

피사체의 속도를 항상 같은 지점으로 만들려면 어떻게해야합니까?

+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