First steps in unity, Astroids control

Hi There,

I’m trying to make my first steps into unity, and for my first project i started a simple asteroids game.
I’ve setup a simple test scene with a spaceship, a space background and a camera follow script (top down follows the ship so it stays in the center of the screen)

Ive created the following script to add the movement

var MovingForward = 0;

// Update every fixed time, Because of rigid body
function FixedUpdate () {
	var maxVelocity : float = 20.00; // maximum velocity of the ship
	var thrustSpeed : float = 10.00; // speed at which the speed is increased
	var breakSpeed : float = 15.00; // speed at which the speed is decreased
	
	
	if(Input.GetButton("Jump")) {
		rigidbody.AddRelativeForce(thrustSpeed,0,0);
		MovingForward ++;
	} else if (!Input.GetButton("Jump")  MovingForward > 0) {
		rigidbody.AddRelativeForce(-10,0,0);
		MovingForward --;
	} else {
		rigidbody.AddRelativeForce(0,0,0);
	}
}

This sort of does what i want the ship to do, when pressing the space bar, accelerate and when releasing the space bar, decreasing till its not moving any more (without a abrupt start)

Of course this code can (and must) be done better, but i have no idea which functions to begin with
therefore i would like some suggestions on how to do this.

Thank you in advanced!

If you Have’nt looked at the 2D Platform demo, there is a good spaceship control in there.

Just wondering why you localized your vars inside the function? :smile:

Good one, ill check it out

If i make them accessible to the editor, when i change the value i have to go true the extra step of changing them in the editor, now i can just fiddle with the number in the script and hit play :slight_smile: i find it much easier when working on a unfinished script