- Home /
Question by
UncoolName · Jan 09, 2015 at 04:28 PM ·
movementaiitween
iTween series of MoveTo()
Good day everyone! I picked up Unity only a month ago so I'm pretty new to it, even if I already developed my first game. Now I'm developing a second one, a 2D car game, and searching for solutions to create car AIs i found iTween. I have an issue with the MoveTo() function. Here's my code:
GameObject[] waypoints = new GameObject[3];
Transform[] waypointsTransform = new Transform[3];
public int laps = 5;
// Use this for initialization
void Start () {
for(int i=0;i<3;i++){
waypoints[i] = GameObject.FindGameObjectWithTag ("Waypoint"+i);
waypointsTransform[i] = waypoints[i].transform;
}
for(int j=0;j<laps;j++){
StartCoroutine(doLap());
}
}
// Update is called once per frame
void Update () {
}
IEnumerator doLap(){
for (int i=0;i<waypoints.Length;i++){
iTween.MoveTo (gameObject, iTween.Hash("x" , waypointsTransform[i].position.x, "y" , waypointsTransform[i].position.y ,"time", 1, "easetype",iTween.EaseType.easeInSine));
yield return new WaitForSeconds(1f);
}
}
Basically I wanna iterate the doLap() function (at the moment I'm just testing 3 waypoints) each lap and use the MoveTo() function to move through my waypoints. The problem is that the result movement of the cars is not fluid, the cars simply stop at each waypoints and then move towards the next one. Is there a way to make it more fluid, maybe defining a path? Thank you in advance and sorry if my code is rough, I'm still learning :)
Comment
Your answer