90 degree turn like in tron games

hello I’m making a simpe car game but I wan’t it to move only in 4 direction N,E,W,S. and turns exactly 90 degrees. is there any script similar to this? Thank you so much to one who can share simple script :slight_smile:

I don’t have a script prepared, but I think you’ll find it very simple. Check out the UnityScript documentation for Vector3 and Transform (specifically Transform.Rotate).

You’ll probably want to make use of Vector3.forward, Vector3.right, etc.

Easily accomplished.

private var speed=10.0;

function Update(){
	// if we dont press a key, dont move. ;)
	var amount=0.0;
	if(Input.GetKey("d")){
		transform.LookAt(transform.position + Vector3.right);
		amount=1.0;
	}
	if(Input.GetKey("a")){
		transform.LookAt(transform.position - Vector3.right);
		amount=1.0;
	}
	if(Input.GetKey("w")){
		transform.LookAt(transform.position + Vector3.forward);
		amount=1.0;
	}
	if(Input.GetKey("s")){
		transform.LookAt(transform.position - Vector3.forward);
		amount=1.0;
	}
	
	transform.Translate(Vector3.forward * amount * speed * Time.deltaTime);
}

Thank you very much MisterB! :slight_smile: I’ll try this out ^^ by the way here’s one of my game still WIP thou. https://dl.dropbox.com/u/20524065/LOMM%20legacy%20web%20game%20(beta)/OZKAR/WebPlayer.html