Remove the Z value of Addforce (C#)

Ok I have a 3 lane cargame - think Spy hunter side on. and I am using AddForce to swap lanes. This works fine.

But what I need to do is Kill the force in in the z axis, allowing it keep it’s speed and Stop the car on each lane - I can Translate it no problem but I want it to move smoothly

Any Ideas? Thanks!

public void switchLanesUp()
	{
		if (zActive == true)
		{
			switch (currentlane)
			{
		        case 1: 
				rigidbody.transform.Translate(0, 0, 0);
				break;	
			case 2: 
				rigidbody.AddForce(Vector3.forward * 200 , ForceMode.Acceleration);
				currentlane = 1;
				break;
			case 3: 
				rigidbody.AddForce(Vector3.forward * 200 , ForceMode.Acceleration);
				currentlane = 2;
				break;				
			}
		
		Debug.Log ("Switched lanes Up " + currentlane);
		}
	}


    Void FixedUpdate() {
    				if (rigidbody.position.z >= 3 )
    				{
    				Debug.Log ("STOP");
    				rigidbody.transform.Translate(0, 0, 0);
    				}	
    }

Hi Prowl,

You want the lanes to be fixed rows, but you want the movement between the lanes to be smooth. Instead of applying force in the direction of a lane, why not use Vector3.Lerp? It will allow you to translate the car to a new position but you translate it using a value that can make the translation smooth.

Or you could use iTween’s MoveTo or MoveBy functions to lerp the car using an easeType. A couple of iTween’s examples use this function.

If you want to stop the ‘Z’ velocity, you can do this:

Vector3 v3 = ridbody.velocity;
v3.z = 0.0f;
rigidbody.velocity = v3;

If your game is going to have curves, @andytouch’s Lerp() is a good suggestion. You can can send an empty game object down the track with the physical car as a child. Then you can Lerp() the Transform.localPosition of the car.