Member-only story
How Game Physics Works: Building a 2D Physics Engine from Scratch in Canvas
Mustafa Morbel
16 min read16 hours ago
We code gravity, collision detection, and slingshot mechanics from the ground up — and then give an honest answer to “what should you actually use in production?”
Press enter or click to view image in full size Physics Engine from Scratch: Slingshot Game. HTML5, JavaScript, WebGL
A few weeks ago, I was reading a game development tutorial. It cheerfully announced: “Physics sounds intimidating… but don’t worry, a physics engine will handle all the math for you!” With a single line of code, the author attached physics to a ball. The ball dropped, bounced off the floor, and everyone went home happy.
That sentence genuinely bothered me.
Because if you don’t understand what happens beneath that single line of code, the engine remains a complete black box. Why does the ball bounce at that exact speed? Why does tweaking gravity suddenly make everything feel floaty or jittery?…