How to make Vehicle AI to change lanes

I am working on a project atm, and I need the vehicle AI to switch lanes. From lane 1 to lane 2 and vice versa. I made a script to make the vehicle stick to a lane, and in update i made it send a flag to the function (0 for first lane 1 for second lane) and make the car move towards that lane. but while moving towards the lane it starts to wobble when it reaches it…
NOTE: the lanes are 2 concentric ellipses-like (it’s a race track)
I am using a waypoint in the middle of the track which moves along it’s z axis as much as the vehicle. I calculate the distance from the waypoint to the vehicle and try too maintain it around a specified distance (band1, which is lane 1 and band2 which is lane2 and band1<band2)
.

I need to get rid of that wobble effect (it changes the steerAngle to make it keep the lane too much too fast)

here’s the code of the function:

function AutoSteer(flag){
	var distance : float;
	distance = Vector3.Distance(reference.transform.position, transform.position);
	if(flag == 0){
		if(distance > band1 + maxDistance){
			colliderFL.steerAngle = MaxSteeringAngle * (band1 + maxDistance - distance) * 0.5;
		}
		else 
			if(distance < band1 + minDistance){
				colliderFL.steerAngle = MaxSteeringAngle * (band1 + minDistance - distance) * 0.5;
		}
		if(Mathf.Abs(colliderFL.steerAngle) > 10){
				if(distance > (band1 + band2)/2)
					colliderFL.steerAngle /= 8;//
				else 
					colliderFL.steerAngle /= -10;
		}
	}
	if(flag == 1){
		if(distance > band2 + maxDistance){
			colliderFL.steerAngle = MaxSteeringAngle * (band2 + maxDistance - distance) * 0.5;
		}
		else 
			if(distance < band2 + minDistance){
				colliderFL.steerAngle = MaxSteeringAngle * (band2 + minDistance - distance) * 0.5;
		}
		if(Mathf.Abs(colliderFL.steerAngle) > 10){
				if(distance < (band1 + band2)/2)
					colliderFL.steerAngle /= 8;
				else 
					colliderFL.steerAngle /= -10;
		}
	}

PS: I am kinda new to unity, and I tried to play around with the values… with no luck. (all code was written by me, feel free to correct me, or offer a better solution) :stuck_out_tongue:

Here is an image that I hope will explain better what I am trying to do.

i think using Ray from the reference object to the vehicle might do the trick, but i don’t quite know how to use it, any help pls?

bump.