- Home /
Animate an object to a new position...
If I am currently using:
transform.localPosition.x = 4;
to instantly transport an object (regardless of where it is) to a new position, how would I make the object gradually move to its new destination?
Answer by · Jan 23, 2011 at 03:06 PM
You could lerp (Vector3.Lerp) between the two positions in a Coroutine.
There is also a popular Unity package called iTween, and it does the heavy lifting for you - all you need to do is learn the specific calls.
For example:
iTween.MoveTo(gameObject,Vector3(4,0,0),2);
This code will move gameObject
to (4,0,0)
over 2 seconds.
I've got the example vector3.lerp working from the reference page (I've made an object move from a start position to an end position) - I don't quite understand the time.time statement though, how can I convert \ modify that to get a configurable speed?
Take a look at the code example in Eric's answer here: http://answers.unity3d.com/questions/6949/can-someone-explain-how-using-time-deltatime-as-t-in-a-lerp-actually-works/6950#6950
Your answer
Follow this Question
Related Questions
Moving an Object towards another Moving Object 2 Answers
Move object in front of another 1 Answer
Decrease distance between 2 objects 3 Answers