AI Car Waypoints - Odd Behaviour...

Hi there,

I am trying to set up a basic system in which my AI cars drive around the track, by way of waypoints. I thiought this would be simple, but the code that I have isn’t working… each time the car hits a waypoint, it slows down and moves to the next. It only gets to a couple of waypoints before coming to a complete stop… any ideas!!!

for (var i = 0; i < Waypoints.length - 1; ++i)
			{
		 		transform.position = Vector3.MoveTowards(transform.position,Waypoints_.transform.position,(fSpeed * Time.deltaTime));_
  •   	}*
    

For anyone else interested in this, here is what I did:

I got rid of the for loop and put an OnTriggerEnter function that when triggered (by car hitting waypoint), increments the waypoint array index. This way, every time a waypoint is hit, the car moves on to the next :slight_smile:

It’s really basic and needs a LOT of waypoints to be reasonably smooth but for a simple game like mine, it’s fine.

Hope this helps someone else!!!