The home of Dino

Box2D Javascript test

I’ve just indulged myself in some physics therapy. I *FINALLY* managed to get a few hours to play with the JavaScript port of the infamous Box2D.js physics library. Not fantastically exciting, but at least it’s a start!

Why is this even remotely interesting? Well, I’ve had a bit of a history with physics engines. Way back in the early days of Flash 5 and AS2, I was pulling together a team to make a pinball game to promote a new Disney movie. A contractor took on the job of writing the physics engine but half way through, he decided his work was too ‘valuable’ and wanted to license it to us instead. Honour and morals are pretty high on my list so that approach didn’t go down too well. So I did what any Creative Director (with barely a C-grade in O-level maths) would do… I decided to make one myself. How hard could it be? Turns out it was quite hard, took lots of “vector maths for dummies” research and annoying my ‘real coder’ colleague Jop with random circles and lines scribbled on napkins. But we got there. I think I OD’d on vector maths a little, hence haven’t been near a physics engine since.

The engine I made was quite ‘creative’ in its approach. It had all sorts of optimisations to make it run on slower computers, especially given how bad browsers where back then. I’ve managed to dig out a debug version (excuse the dead fonts). This version has the visualisation of my “hit zone optimisation” turned on. As the game starts up, it registers every element of the table and every section of curve. It only bothers to work out which areas to properly calculate based on the ball’s immediate surroundings. It sped the calculations up something like 400% when I switched it on for the first time. Click on the image below to launch it in good old-fashioned Flash and you’ll see how it highlights first the quarter of the table to concentrate on, then the individual areas within. Just click yo get started and use the cursors (down arrow to pull the spring back). Have fun!

wildhogs

Add comment