- Home /
Increase forward speed
I have an object that I want to give a forward speed when the game starts. The forward speed needs to increase every 5 seconds. I tried everything, but no joy.
var speed : float = 5.0;
var increaseAmount : int = 5;
InvokeRepeating("IncreaseSpeed", 2, 2);
function IncreaseSpeed ()
{
speed += increaseAmount;
}
function Update ()
{
transform.Translate(Vector3.forward * Time.deltaTime);
}
This is the script I found, but it's not working. Someone who can help me please?
Thanks in advance
Answer by aldonaletto · Apr 23, 2013 at 12:09 AM
Just replace Rotate with Translate, for instance:
function Update(){
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
Answer by iSpy · Apr 23, 2013 at 07:31 AM
well i did same thing just with buttons for example w increases object speed and s decrease it
public Transform mover; public float maxSpeed = 0.1f; public float curentSpeed = 0f; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if(Input.GetKey(KeyCode.W)) { adjustCurentSpeed(+0.001f); } if(Input.GetKey(KeyCode.S)) { adjustCurentSpeed(-0.001f); } mover.transform.Translate(0, 0, curentSpeed); } public void adjustCurentSpeed(float adj) { curentSpeed += adj; if(curentSpeed <=0f) { curentSpeed = 0f; // if speed goes below 1 it stays 0, doesnt go negative } if (curentSpeed > maxSpeed) { curentSpeed = maxSpeed; // curent speed never goes over max speed } if (maxSpeed < 0.1f) { maxSpeed = 0.1f; } }
you can just edit it to auto increase it over time without key input, hope it helps.
Your answer
Follow this Question
Related Questions
fly speed , increasing speed 1 Answer
Move Object A towards Object B at a definite speed 1 Answer
Increase ball speed by time 1 Answer
move box forward 1 Answer
How should I move an object that parents on collision? 1 Answer