Making the car stick to the road in unity3d car tutorial.

Hi all,

Im playing with the unity car tutorial, its pretty good, but the car seems to fly off the track allot, be it on hills or because of crashes.

Is there a way to make the car ‘stick’ to the road?, it would give it a much more arcade feel.

Thanks in advance!
(also posted in scripting)

This is not allowed; please read the Unity Developer Network rules (section 1b). I’ve deleted the duplicate.

–Eric

No matter, I just put the gravity up, now if I could just stop the car driving up the walls when its at full speed :slight_smile:

Lock some rotation axis on the rigidbody component or use mathf.clamp

function Update () {
 var xMove : float = Input.GetAxis("Horizontal") * Time.deltaTime * 20;
 transform.Translate(Vector3(xMove,0,0));
 transform.position.x = Mathf.Clamp(transform.position.x, -10, 10);
}

This code comes with the videotutorial at unity3dstudent.com

http://www.unity3dstudent.com/2010/11/beginner-b26-using-mathf-clamp-to-restrict-values/

You would obviously need to clamp transform.rotation instead of transform.position

That sounds like exactly what I need, Thanks!