# How do I accelerate a gameObject based on time?

I am spawning gameObjects that are falling. I would like to accelerate their fall speed based on how much time has passed, such as every 60 seconds that falling rate increases.

``````var acceleration : float;
var maxSpeed : float;
var seconds : int = Time.time;

function Update() {
transform.Translate(0, acceleration * Time.deltaTime,0);
if (acceleration > maxSpeed) {
acceleration += 1;
}
}
``````

This what I came up with. How do I do it?

Acceleration, by definition, is the variation of speed by second.
Speed units are meter/second, therefore, acceleration units are meter/(second^2).

What you need to do is to have two parameters to determine the variation in an object position : speed and acceleration.

If you look at gravity for example, it is estimated at 9.81 m/s^2. That’s an acceleration.
To simulate something similar, your speed has to vary in time too.

Here’s a quick and dirty script that demonstrates what I say :

``````public float gravity = -9.81f;
private float speedY = 0f;

private void Update () {
Vector3 newPos = transform.position;
newPos.y += speedY * Time.deltaTime;
speedY += gravity * Time.deltaTime;

transform.position = newPos;
}
``````

At each frame, you update not only the position, but the speed too, according to the defined acceleration