- Home /
Make something arrive at position in exactly X seconds?
So I want to have an object arrive at a position in exactly X seconds (not sooner or later), how would I go about calculating this?
Comment
Best Answer
Answer by syclamoth · Jan 25, 2012 at 11:09 PM
Given that you know the object's starting position and its desired end position, you can use something like this:
IEnumerator MoveToPosition(Vector3 startPos, Vector3 endPos, float moveTime)
{
float curTime = 0;
while (curTime < moveTime)
{
transform.position = Vector3.Lerp(startPos, endPos, curTime / moveTime);
curTime += Time.deltaTime;
yield return null;
}
}
Answer by Tasarran · Jan 25, 2012 at 11:08 PM
Check the Unify Wiki, I use this, and it works great.
You can do it over time or by speed.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to calculate delta offset time between race cars? 0 Answers
Achieving consistent jump height regardless of vertical velocity 2 Answers
Find Vector3 perpendicular to Vector3 A in direction of Vector3 B 1 Answer
Calcultate spawn position based on spawn volume's rotation 2 Answers