- Home /
Question by
Goldragon979 · Jun 18, 2010 at 07:50 PM ·
positionloopmovetranslate
Loop from Point A to Point B after Point C
Any idea how do I move an object in loop from point A to Point B when it reachs a Point C?
Thanks.
Comment
Answer by Tetrad · Jun 18, 2010 at 09:25 PM
http://itween.pixelplacement.com/
Look at the "callback functions" demo.
Answer by StephanK · Jun 18, 2010 at 08:34 PM
Not sure if that's what you want, but to check if Point C was reached you can use a Trigger. (Collider that is setup as a trigger) To move something from A to B over a fixed amount of time you can write a Coroutine which is starte when Point C is reached. The coroutine would look something like this:
IEnumerator MoveTo(Vector3 start, Vector3 target, float time) {
float startTime = Time.time;
while (transform.position != target) {
transform.position = Vector3.Lerp(start, target, (Time.time - startTime) / time);
yield return 0;
}
}
To start the coroutine the trigger object will need a script like this:
void OnTriggerEnter(Collider c) {
c.GetComponent<MyScript>().StartCoroutine(MoveTo(start, target, time));
}