Advertisement Β· 728 Γ— 90

Posts by Jedidiah

Doing gravity right

Now you may be thinking: "baah, I know how to do gravity.." but there's a big flaw in the commonly used Euler's method to handle the gravity (or other forces). Even all the Quake games have this problem. Then what is it? If you have more frames per second in Quake, your player will run faster and jump higher. There are some places in Quake where you can't jump high enough if you don't have enough frames per second. Sounds odd, right?

Most of the programmers do the gravity something like this:

velocity = velocity + gravity*delta_time
position = position + velocity*delta_time

The algorithm above is ok but when delta_time changes or delta_time is too high, it causes many unwanted problems. Gravity adding should actually be done like this:

velocity = velocity + gravity*delta_time/2
position = position + velocity*delta_time
velocity = velocity + gravity*delta_time/2

That's it.. but you need proof, right?

Doing gravity right Now you may be thinking: "baah, I know how to do gravity.." but there's a big flaw in the commonly used Euler's method to handle the gravity (or other forces). Even all the Quake games have this problem. Then what is it? If you have more frames per second in Quake, your player will run faster and jump higher. There are some places in Quake where you can't jump high enough if you don't have enough frames per second. Sounds odd, right? Most of the programmers do the gravity something like this: velocity = velocity + gravity*delta_time position = position + velocity*delta_time The algorithm above is ok but when delta_time changes or delta_time is too high, it causes many unwanted problems. Gravity adding should actually be done like this: velocity = velocity + gravity*delta_time/2 position = position + velocity*delta_time velocity = velocity + gravity*delta_time/2 That's it.. but you need proof, right?

Results in practice

Here is a "jumping" parabola with different delta times, using the bad algorithm. The picture on the right corresponds almost exactly to Quake. As you can see, you can't jump in Quake if you have less than 3 fps.

(Illustration showing changes in the arc of a jump depending on framerate)

As delta time (dt) gets higher, the jumping curve gets lower.

Now here are results with the new algorithm:

(Illustration showing the arc of a jump staying the same)

Quite nice, don't you think? Accelerating physics are no longer approximation!

Remember that you should do all the accelerating forces like described above, not just gravity.

Results in practice Here is a "jumping" parabola with different delta times, using the bad algorithm. The picture on the right corresponds almost exactly to Quake. As you can see, you can't jump in Quake if you have less than 3 fps. (Illustration showing changes in the arc of a jump depending on framerate) As delta time (dt) gets higher, the jumping curve gets lower. Now here are results with the new algorithm: (Illustration showing the arc of a jump staying the same) Quite nice, don't you think? Accelerating physics are no longer approximation! Remember that you should do all the accelerating forces like described above, not just gravity.

Integrating to the same results

The proving of the formula can also be done using integration (of course, because you are calculating areas..)

After integrating you'll get this formula:

pos = pos + 1/2*acc*dt^2 + vel*dt
vel = vel + acc*dt

Note that pos = position, vel = velocity, acc = acceleration and dt = delta_time

And optimizing that formula leads to this:

temp = acc*dt
pos = pos + dt*(vel + temp/2)
vel = vel + temp

This equals to the second formula given at the beginning of this document.

Integrating to the same results The proving of the formula can also be done using integration (of course, because you are calculating areas..) After integrating you'll get this formula: pos = pos + 1/2*acc*dt^2 + vel*dt vel = vel + acc*dt Note that pos = position, vel = velocity, acc = acceleration and dt = delta_time And optimizing that formula leads to this: temp = acc*dt pos = pos + dt*(vel + temp/2) vel = vel + temp This equals to the second formula given at the beginning of this document.

I dug up this very helpful old article on the internet archive that I think explains the problem and solution extremely clearly using the way Quake handles gravity as an illustration
web.archive.org/web/20160719...

10 months ago 355 82 18 7

I've never even had a driving lesson but I'm in the UK. I imagine it's quite a different prospect in the US!

11 months ago 1 0 0 0
Head and shoulders portrait of a pigeon with gorgeous iridescent green and purple neck, and orange eye.

Head and shoulders portrait of a pigeon with gorgeous iridescent green and purple neck, and orange eye.

When you've got it πŸ”₯
#birds

11 months ago 314 16 11 1
Preview
a man with a mustache is singing into a microphone and saying `` bicycle ... bicycle '' . Alt: Short gif from movie showing Freddie Mercury (Rami Malek) singing into a microphone ``bicycle... bicycle''

Absolutely! πŸš‹πŸšŽπŸš²πŸš²

11 months ago 1 0 1 0

Here's a discord around Zines and Zine Making. Lots of different potential rabbit holes. discord.gg/7UhQU4Sg

11 months ago 1 0 1 0
A Caroll diagram consisting of four rectangles arranged in a square.
The Y axis is labelled MOVE and split into FAST and SLOW.
The X axis is labelled THINGS and split into BREAK and FIX

Top left image: (Move Fast and Break Things) Tech Bro 
Bottom left image: (Move slow and break things) Runaway Steamroller 
Top right image: (Move fast and fix things) Emergency Plumber
Bottom left image: (Move slow and fix things) Grandpa with a toolbox

A Caroll diagram consisting of four rectangles arranged in a square. The Y axis is labelled MOVE and split into FAST and SLOW. The X axis is labelled THINGS and split into BREAK and FIX Top left image: (Move Fast and Break Things) Tech Bro Bottom left image: (Move slow and break things) Runaway Steamroller Top right image: (Move fast and fix things) Emergency Plumber Bottom left image: (Move slow and fix things) Grandpa with a toolbox

My cartoon for this week's @newscientist.com

1 year ago 8899 1423 64 60
Nuthatch eating suet pellets on a mossy wall

Nuthatch eating suet pellets on a mossy wall

Hi πŸ‘‹
Little Nuthatch!
I love how it looks like it's wearing a bandit's mask!
#birds #photography #wildlifephotography #photographers

1 year ago 218 12 7 0
Advertisement
Post image Post image Post image Post image

Some of the Alba Wagtail still in the flock in Whimbrel Field yesterday #LytchettFields #DorsetBirds @harbourbirds.bsky.social

1 year ago 12 2 0 0
Dave Gorman: Why the Calendar Makes No Sense | Modern Life is Goodish
Dave Gorman: Why the Calendar Makes No Sense | Modern Life is Goodish YouTube video by Dave Gorman

I think you'd also like Dave Gormans idea that also solves that problem youtu.be/vunESk53r5U

1 year ago 0 0 0 0

Anyone looking for a top class web developer? UK based

1 year ago 4 2 0 0

Reposting as I had a typo on the demo link. Thanks for letting me know @stefanmatei.com‬ the link above should be working now.

1 year ago 3 0 1 0
Screenshot of my game of life component with the basic settings, showing light green cells on a dark green background

Screenshot of my game of life component with the basic settings, showing light green cells on a dark green background

Another screenshot of my game of life web component, this one is rainbow coloured and instead of the dead cells being removed on the next frame on this version they are just left and overdrawn

Another screenshot of my game of life web component, this one is rainbow coloured and instead of the dead cells being removed on the next frame on this version they are just left and overdrawn

I wanted to play a bit more with #WebComponents so I made a web component that renders Conway’s Game of Life in an offscreen canvas.

Code: github.com/Jedidiah/gam...
Demo: jedidiah.dev/journal/2025...

1 year ago 7 0 1 0

Relatedly I also wrote a little post on using generator functions for #CellularAutomata in #javascript.

jedidiah.dev/journal/2025...

1 year ago 2 0 0 1
Preview
ANOM – Darknet Diaries In this episode, Joseph Cox tells us the story of ANOM. A secure phone made by criminals, for criminals.

Listened to a really interesting interview about that darknetdiaries.com/episode/146/ would quite like to pick his book up.

1 year ago 1 0 1 0
Advertisement

Your weekend reminder that I have a starter pack entirely full of Katharines* who work on climate

* alternate spellings are permitted

go.bsky.app/Po82tCi

1 year ago 1130 162 80 16

Me too! I added a blogroll on my site to try and help normalise it again
jedidiah.dev/blogroll/

1 year ago 1 0 1 0

`Unable to make progress running work. There are items queued for execution but none of them can be started`

I'v never had an error message so closely reflect my own internal state. Time for a coffee!

1 year ago 0 0 0 0
Post image

Another photo from my archives.
Banded stilts.
They always remind me of ballerinas 🩰

2 years ago 79 19 3 1
Post image

Day 3 of Marvel UK themed Inktober and next up is Shevaun Haldane, Dark Angel, created by Bernie Jaye and Geoff Senior

2 years ago 2 2 1 0
Long tailed tit looking fabulous on a branch.

Long tailed tit looking fabulous on a branch.

#intro Hello πŸ‘‹ I'm a #contract software developer in Glasgow Scotland, I work mostly in #frontend and #mobile. I have a background in #design and #animation

I love learning new things and my current fascination is #birds

jedidiah.dev

2 years ago 10 1 2 0