x


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.

more ▼

asked Jun 18 '10 at 07:50 PM

Goldragon979 gravatar image

Goldragon979
38 2 2 7

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

http://itween.pixelplacement.com/

Look at the "callback functions" demo.

more ▼

answered Jun 18 '10 at 09:25 PM

Tetrad gravatar image

Tetrad
7.2k 27 37 89

(comments are locked)
10|3000 characters needed characters left

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));
}    
more ▼

answered Jun 18 '10 at 08:34 PM

StephanK gravatar image

StephanK
6k 39 53 93

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x888
x500
x296
x207

asked: Jun 18 '10 at 07:50 PM

Seen: 1158 times

Last Updated: Jun 18 '10 at 07:50 PM