High Speed

I’m making a spaceship for my game and I’m using that code to control the ship ;

`var Ucak:Rigidbody;
var speed:int=5;
var speedu:int=5;
var speedd:int=5;
var speedr:int=5;
var speedl:int=5;
function Update () {

//Ucak.AddForce(Vector3.forward * 10);
direction=transform.forward * Time.fixedDeltaTime * speed;
transform.Translate(direction);

if(Input.GetButton(“Down”)){
transform.Rotate(Vector3.right * 25 * Time.fixedDeltaTime);
direction=transform.up * Time.fixedDeltaTime * speedu;
transform.Translate(direction);

}

if(Input.GetButton(“Up”)){
transform.Rotate(Vector3.right * -25 * Time.fixedDeltaTime);
direction=transform.up * Time.fixedDeltaTime * speedd;
transform.Translate(direction);

}

if(Input.GetButton(“Right”)){
transform.Rotate(Vector3.forward * 25 * Time.fixedDeltaTime);
direction=transform.right * Time.fixedDeltaTime * speedr;
transform.Translate(direction);

}

if(Input.GetButton(“Left”)){
transform.Rotate(Vector3.forward * -25 * Time.fixedDeltaTime);
direction=transform.right * Time.fixedDeltaTime * speedl;
transform.Translate(direction);

}
Debug.Log(speedu);
} `

Ucak means spaceship

And that ship is flying so FAST , so much … And I looked to the “speed” variable ingame with debug.log and it says speed=5000 but I was set it to 5 ?

How can I fix it ?

You should only use Time.fixedDeltaTime actually inside the FixedUpdate loop - otherwise it will give you funny values. The Update loop happens every frame, whereas the FixedUpdate loop only happens every physics step (however long that is). Try replacing fixedDeltaTime with deltaTime every time you call it- this will give you the correct value.

In fact, there is very rarely any reason to call fixedDeltaTime, since when deltaTime gets called from within a FixedUpdate loop, it returns the fixedDeltaTime anyway! The only time you need to manually specify is if you need to know the exact number for whatever reason, not (as you are using it here) as a way of making your actions framerate independent (as, indeed, it is usually used).

As for your 'speed = 5000' thing, I can't really help you with that one since there is nothing in the code you showed us that could possibly cause such a thing- is there something else that you're not showing us? Remember that the value you assign in the editor will override the value you see in the script, so make sure you haven't done something funny in the inspector.