# My Spaceship Accelerations not working?

I made a script in c#, which worked fine, then i needed to do a different script which required java, so i rescripted this into Java! This is the java version, for somereason when im holding space to Accelerate, ITS NOT WORKING?? it should be??? help, look at the //acceleration part
#pragma strict

``````	var speed = 0;
var maxSpeed = 1;
var minSpeed = 0;
var breakPower = 0.5f;
var accelSpeed = 0.1f;

var rotatePower = 1;

// Use this for initialization
function Start () {

}

// Update is called once per frame
function Update () {

//--------------------------------------------------------

//Acceleration
if (Input.GetKey("space")) {
speed += accelSpeed * Time.deltaTime;
}
// MoveForward At the Speed
transform.Translate(0, 0, speed);

//Make sure you can only go upto the max speed
if (speed > maxSpeed) {
speed = maxSpeed;
}

//Make sure the slowest you go is your MinSpeed

if ( speed < minSpeed) {
speed = minSpeed;
}
// Braking

if (Input.GetKey("left shift")) {
speed -= breakPower * Time.deltaTime;
}

//--------------------------------------------------------------

//Rotating up + down, make sure your at a high enough speed also

if (speed > 0.1) {

if ( Input.GetKey("w")) {
transform.Rotate(rotatePower, 0, 0);
}
if ( Input.GetKey("s") && speed > 0.35f) {
transform.Rotate(-rotatePower, 0, 0);
}
}

//Roting The Roll

if ( speed > 0.1) {

if ( Input.GetKey("a")) {
transform.Rotate(0, 0, rotatePower);
}
if ( Input.GetKey("d")) {
transform.Rotate(0, 0, -rotatePower);
}
}
//Turning on the flat axis

if (speed > 0.1) {

if ( Input.GetKey("q")) {
transform.Rotate(0, rotatePower, 0);
}
if ( Input.GetKey("e")) {
transform.Rotate(0, -rotatePower, -0);
}
}

//-------------------------------------------------------------
}
``````

The likely problem is here:

``````var speed = 0;
var maxSpeed = 1;
var minSpeed = 0;
var breakPower = 0.5f;
var accelSpeed = 0.1f;
``````

When you don’t specify a type, the compiler infers a type from the parameter. Since you are assigning an integer to ‘speed’, ‘maxSpeed’ and ‘minSpeed’, the compiler makes these variables integers. If an integer was 3, when you add 0.1 to that integer, it is still 3.

You can fix it by changing what is assigned:

``````var speed = 0.0;
var maxSpeed = 1.0;
var minSpeed = 0.0;
``````

And/or you can specify the type for the variables:

``````var speed : float = 0;
var maxSpeed : float = 1;
var minSpeed : float = 0;
``````