Proper Way To Handle Gravity?

I have been thinking about a proper way to handle gravity in a 3d shooter.

Imagine your character is 16 units in height. The average human is say… 2 meters tall. This means that 1 meter is 8 units. the ratio is 1:8.

If gravity is expressed as 9.81 m/s^2 I believe then it would be equal to 78.48 units/s^2

However, this is only your acceleration per second…

If a game is running at 60 frames per second, this is where I become quite shaky, because you cannot just divide the gravity (78.48) by 60, and treat it as normal…

Assuming this conventional way of handling gravity is correct:

velocity.z += gravity;
z -= velocity.z;

How would you take into account there being 60 calculations per second?

Yes, I have tried dividing the 78.48 by 60, but it does not feel correct…

First of all, why uses something as abstract as “units” anyways if you want to convert to meters.

Now about your code, no it is not correct :slight_smile: and yes you can just divide the gravity by 60, because thats is normal.


g = 9.81 m/s^2

v (m/s)

//you can not add a acceleration to an velocity so ...
Vd = A * td
m/s = m/s^2 * s

A: in your case g
td: your time delta
Vd: is your velocity delta

Also, the following formula is more correct for a constant acceleration like gravity:


val deltaVel = GRAVITY * timeDelta
entityVelocity = (2 * entityVelocity + deltaVel) / 2

That’s exactly what I needed! Thanks! :slight_smile:

2 meters tall on average?
Are you from Holland?

Also, don’t forget

fun > correctness as such “pseudo realism” > “realism”

This is especially true if Your game has a physics simulator.
Noone plays Your game if it’s not fun, but noone cares if You cheat on gravity and nudge the objects onto right path from time to time

People are pretty close to that in Canada as well.

All this does is halve the gravity? The velocity verlet works well:


// acc_i is the acceleration before the timestep, acc_f is the acceleration after. If they are the same (constant acceleration) then use acc = acc_i = acc_f and:
// vel += acc;
pos += vel*t + 0.5*acc_i*t*t;
vel += 0.5*(acc_i + acc_f)*t;

Edit: forgot a t in the velocity formula.

His was actually spot on.
I checked using d = (1/2g)*(t^2)

I’m not sure exactly how you checked it but his method:

dv = gt
v = (2
v+dv)/2

is equivalent to:

v = (2v+gt)/2 = v + (g/2)*t

i.e. in 1 unit of time the velocity is changing by g/2, not g.

arg sry, yes you are right I messed up, should have checked what I was writing.

The correct way of doing things with const acceleration is:


val oldVel = velocity
velocity += gravityAcc * dTime
position += (oldVel + velocity) / 2 * dTime

and found the old blog post I tried to remember the first time
http://lolengine.net/blog/2011/12/14/understanding-motion-in-games