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!