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.
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...
09.06.2025 03:41
π 356
π 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!
02.05.2025 08:33
π 1
π 0
π¬ 0
π 0
Head and shoulders portrait of a pigeon with gorgeous iridescent green and purple neck, and orange eye.
When you've got it π₯
#birds
25.04.2025 03:39
π 314
π 16
π¬ 11
π 1
Here's a discord around Zines and Zine Making. Lots of different potential rabbit holes. discord.gg/7UhQU4Sg
24.04.2025 00:39
π 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
My cartoon for this week's @newscientist.com
13.04.2025 13:55
π 8905
π 1425
π¬ 64
π 60
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
19.03.2025 07:17
π 218
π 12
π¬ 7
π 0
Some days you just wanna give up , let everything go and follow the light inside of a red cabbage
07.03.2025 20:45
π 8569
π 1530
π¬ 75
π 123
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
21.02.2025 09:43
π 0
π 0
π¬ 0
π 0
Anyone looking for a top class web developer? UK based
27.01.2025 15:55
π 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.
16.01.2025 22:03
π 3
π 0
π¬ 1
π 0
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
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...
16.01.2025 22:01
π 7
π 0
π¬ 1
π 0
Relatedly I also wrote a little post on using generator functions for #CellularAutomata in #javascript.
jedidiah.dev/journal/2025...
16.01.2025 21:39
π 2
π 0
π¬ 0
π 1
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
12.01.2025 03:43
π 1131
π 162
π¬ 80
π 16
Me too! I added a blogroll on my site to try and help normalise it again
jedidiah.dev/blogroll/
21.12.2024 03:46
π 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!
04.12.2024 16:39
π 0
π 0
π¬ 0
π 0
Another photo from my archives.
Banded stilts.
They always remind me of ballerinas π©°
19.10.2023 23:04
π 80
π 19
π¬ 3
π 1
Day 3 of Marvel UK themed Inktober and next up is Shevaun Haldane, Dark Angel, created by Bernie Jaye and Geoff Senior
03.10.2023 23:30
π 2
π 2
π¬ 1
π 0
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
13.09.2023 12:41
π 10
π 1
π¬ 2
π 0