Jedidiah's Avatar

Jedidiah

@jedidiah.dev

Software developer, dabbler in illustration, photography and animation. Moonlighting as a maker of games. Learning about birds. β«Έ he/him 🌍 Glasgow, Scotland πŸ”— https://jedidiah.dev/ 🦣 https://hachyderm.io/@jedidiah

143
Followers
637
Following
11
Posts
09.09.2023
Joined
Posts Following

Latest posts by Jedidiah @jedidiah.dev

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...

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.

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
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! πŸš‹πŸšŽπŸš²πŸš²

24.04.2025 00:52 πŸ‘ 1 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0

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

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

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
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

19.03.2025 07:24 πŸ‘ 12 πŸ” 2 πŸ’¬ 0 πŸ“Œ 0
Post image

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
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

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...

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
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.

14.01.2025 09:39 πŸ‘ 1 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0

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
Post image

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

19.10.2023 23:04 πŸ‘ 80 πŸ” 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

03.10.2023 23:30 πŸ‘ 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

13.09.2023 12:41 πŸ‘ 10 πŸ” 1 πŸ’¬ 2 πŸ“Œ 0