2017-10-14 21 views
0

나는 addforce없이 강체가없는 캐논볼 패턴으로 물체를 움직입니다. 나는 포탄이 적당한 시간에 목적지에 도달하기 위해 얼마나 빨리 움직여야하는지 알아야합니다. 지금까지Unity3d에서 특정 시간에 이동 거리가 필요한 경우, Sin()으로 대포를 굴리는 방법

내 코드 :

moveTimer += Time.deltaTime * ballSpeed; 
Vector3 currentPos = Vector3.Lerp(startPos, endPos, moveTimer); 
currentPos.y += height * Mathf.Sin(Mathf.Clamp01(moveTimer) * Mathf.PI); 
this.transform.position = currentPos; 

내가 증가 'ballSpeed'고, 슛이 같은 곡선을 따라하지만 빨리 알고 있습니다. 정확히 10 초 안에 endPos에 도착하기를 원한다면 ballSpeed를 어떻게 계산해야합니까?

미리 감사드립니다.

답변

2
ballSpeed = 1f/10f; // duration 10s 
... 
moveTimer += Time.deltaTime * ballSpeed; 
Vector3 currentPos = Vector3.Lerp(startPos, endPos, moveTimer); 
currentPos.y += height * Mathf.Sin(Mathf.Clamp01(moveTimer) * Mathf.PI); 
this.transform.position = currentPos; 
+0

감사합니다. 편집하기 전에 거리에 대한 정보를 추가 한 것을 보았지만이 정보는 잘 작동합니다. 고맙습니다! – Quarty