How to stop my car on impact.

I have been working on this 2 player racing game and I have the most set up all I got to do is add the walls… Here is my code:

#pragma strict

var ArrowKeysToMove 		= 		true;
var WASDToMove 				= 		false;
var TopSpeedControl    		= 		true;

var EngineSound 			: 		AudioClip;

var Speed 					= 		0;   					// You Cur Speed...

var TopSpeed 				= 		100;					//When your Speed Hits your Top speed the car will stay at "TopSpeed"

var BreakTime 				= 		1;						//BreakSpeed Is how fast you Break.. I would say the best stop for it is "1" or "2" - Fast

var TurnSpeed 				= 		1;						//TurnSpeed is how fast you turn. IF you hit TopSpeed it will go to "1" If you Are under topSpeed it will stay at "2" - faster 

var aTexture : Texture;
  
      
private var toggleImg 		: 	boolean 	= false;
private var OnBost 			= 	false;
private var IsMoving 		= 	false;
private var UnderSpeed 		: 	int;



InvokeRepeating("IsDiving", .0001, 1.625);




function Start () {

	UnderSpeed = TopSpeed;
	UnderSpeed -= 10;
}
function IsDiving() {

	if(IsMoving == true) {
		if(Speed <= 0) {
		
			Speed = 10;
		
		}
	
		if(Speed <= 40) {
			Speed += 5;
		}
		if(Speed <= TopSpeed) {
			
				Speed += 10;
		
		}
		
		
		}else {
	
		if(Speed >= 10) {
	
			Speed -= 10;
	
		}

				
	}
	if(Speed >= TopSpeed) {
	
		Speed = 100;
	
	}
	
	if(Speed <= TopSpeed) {
	if(Speed >= 10) {	
			
			audio.clip = EngineSound;
			audio.Play();
	}	
	}
}

function Update () {


	//////////////////////////////////////////////////If The wasd to move var is TURE then it will do this witch lets you control the car using W(up), A(feft), S(), D(Right)
	if(WASDToMove == true) {
	if(Input.GetKey ("left ctrl")) {
	if(Speed >= -24) {
	
		Speed -= BreakTime;
	
	}
	}
	
	transform.Translate(Time.deltaTime * Speed, 0, 0);
	
	
	
	if(Input.GetKey ("w")) {

		IsMoving = true;

	}else {
	
		IsMoving = false;
		
	}
	
	if(Input.GetKey ("s")) {
		
		transform.Translate(-.4, 0, 0);
	
	}
	if(Input.GetKey ("a")) {
		
		transform.Rotate(0, -TurnSpeed, 0);
	
	}
	if(Input.GetKey ("d")) {
		
		transform.Rotate(0, TurnSpeed, 0);
	
	}
	}
	
	
	
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////If the Arrow keys use is on then it will set of this witch lets you control with arrow keys
	if(ArrowKeysToMove == true) {
	if(Input.GetKey ("right ctrl")) {
	if(Speed >= -24) {
	
		Speed -= BreakTime;
	
	}
	}
	
	transform.Translate(Time.deltaTime * Speed, 0, 0);
	
	
	
	if(Input.GetKey ("up")) {

		IsMoving = true;

	}else {
	
		IsMoving = false;
		
	}
	
	if(Input.GetKey ("down")) {
		
		transform.Translate(-.4, 0, 0);
	
	}
	if(Input.GetKey ("left")) {
		
		transform.Rotate(0, -TurnSpeed, 0);
	
	}
	if(Input.GetKey ("right")) {
		
		transform.Rotate(0, TurnSpeed, 0);
	
	}
	if(TopSpeedControl == true) {
	if(Speed == TopSpeed) {
	TurnSpeed = 1;
	}
	if(Speed <= UnderSpeed) {
	TurnSpeed = 2;
	}
	}
	}
	//Make it to where when you press on "ArrowKeysToMove" or "WASDToMove" then it will set the OTHER one to false
	if(ArrowKeysToMove == true) {
	WASDToMove = false;
	}
	if(WASDToMove == true) {
	ArrowKeysToMove = false;
	}
	
}
function OnTriggerEnter  (other : Collider) {
	
	if(other.tag == "Wall") {
	
		
		print("You Hit A wall");
		Speed = -10;
	
	}
	
	if(other.tag == "Bost") {
	
		OnBost = true;
		print("Bost");
		Speed += 50;
	
	}
	
}
function OnGUI() {

     toggleImg = GUI.Toggle(Rect(00, 00, 50, 50), toggleImg, aTexture);
		
}

is there a function where you when you hit some thing that will happen?

right know i got it to when the walls are a trigger and when you enter.
I dont know if i should be using "transform.Translate(x, x, x);
i would just make it a plane wall it just flips the car… if you know any way to fix this bug it would really help well thanks :smiley:

if you need to know more or something just tell me :smiley:

How about just putting colliders on your car and walls?

Your code is quite hard to follow, being so much of it. I have a feeling your overcomplicating a usually simple process. :stuck_out_tongue:

At first glance I would say you have to set IsMoving to false.

Because it looks like, even if you hit the wall, if your still pressing forwards, then the speeds will still be added. You set the speed to -10 when you hit the wall, but your code higher up just sets the speed to speed +15 if your under 40, and +10 if your over.