Unity – Car Driving – Basic

A very simplistic car driving on the X-Y plane


#pragma strict 

        // A very simplistic car driving on the x-y plane
	var speed : float = 10.0;          // to change car speed
	var rotationSpeed : float = 100.0; // to change rotation speed
	
	function Update () {
		// Get the horizontal and vertical axis.
		// Keys: A D to rotate left right - W: go!  
		// The value is in the range -1 to 1
		var translation : float = Input.GetAxis ("Vertical") * speed;
		var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
		
		// Make it move 10 meters per second instead of 10 meters per frame...
		translation *= Time.deltaTime;
		rotation *= Time.deltaTime;
		
		// Move translation along the object's x-axis
		transform.Translate (0, translation, 0);
		// Rotate around our z-axis
		transform.Rotate (0, 0, -1*rotation);
	}