Predicting circle line collisions



In my previous collision detection post (in what I expect will become a series), I talked about predicting whether two objects would collide in between frames. This is to avoid the situation where the objects are moving so fast that they pass through each other before you’ve had a chance to see if they’re overlapping. This is often known as a sweep test (amongst other things!)

And I showed how you could predict collisions between a 2D circle and a vertical line but what about lines that aren’t vertical? How do you work out collisions between circles and lines of any angle?

Continue reading “Predicting circle line collisions”

Predictive collision detection techniques



In preparation for my upcoming Flash game programming training courses, I’m getting my head back into game physics, and I so I thought I’d share some useful collision detection methods I’ve discovered over the last few years.

Reactive collision detection

Collision detection in Flash games often occurs after things have moved. So you have a circle (usually a 2D representation of a ball) and you’re moving it towards a vertical line on the side of the screen (representing a wall). Every frame, you update its position and check whether it’s overlapping the wall.

Which is great, but of course if the ball is moving fast it may go from one side of the wall all the way to the other side between frames and no collision is detected. One way to get around this is to split up the movement of the ball into small segments and run this check several times between frames. This seems pretty inelegant to me so I have always strived to use predictive collision detection methods where my maths knowledge has allowed me! (This is also known as sweep testing, frame independent or continuous collision detection (CCD)).

Predicting when things will collide before you move them

So rather than just check whether the ball is intersecting with the wall between renders, we actually check the velocity of the ball to see at what point in time it would hit the wall if it continued in the direction it’s going.
Continue reading “Predictive collision detection techniques”

Learn how to program Flash games

I’ve just set up a brand new 2 day training course to teach you everything I know about making Flash games! It’s in Brighton (of course) on the 8th and 9th of February (the week after the Papervision training).

Flash games programming training

We’ll be covering all the fun stuff, collisions, physics, optimisation, actionscript animation and working with graphical assets and sound. I’ve just put the first draft of the itinerary together and I’m really excited about it – it’s all of my very favourite things about programming ActionScript. πŸ™‚

Flash games programming training

And of course we’ll be using my portfolio of games as case studies, including Jambuster (BBC), Extreme Pamplona (Sure for Men), The Simple Game (Philips) and we’ll even be diving into the code for LunarLander3D in detail.

Early bird pricing is only Β£250 for 2 days and there are 4 student places, so please book early to ensure your space.

Flash Games Programming in Brighton information and booking.

Technical Reviewer: Making Things Move part 2

Whenever anyone asks me to recommend a good book to learn ActionScript 3, I always tell them to run on over and buy a fresh copy of Keith Peters’ Making Things Move. In fact I was quite gutted when the first AS2 version came out; I’d spent the previous 2 years working out how to do most of that stuff for myself from scratch. If only it had come out earlier I would have saved all that effort!

So I was delighted when those charming chaps at FriendsOfEd asked me to be the Technical Reviewer for the latest version of the book!

Not only do I get to see the book before anyone else, I also get paid for it! Oh and I do have to actually suggest some stuff every now and again.

I must say it’s looking pretty damn good so far… of course I can’t reveal the exact content of the book, but you can read all about it here [link no longer available], and even pre-order it here!

And here’s Keith’s take on it. Oh and some bullet points, just to get you excited :

  • ActionScript for Flash Player 10 3D and Inverse Kinematics
  • New drawing API commands and PixelBender
  • Isometric world creation
  • Artificial intelligence including pathfinding and steering/flocking behaviors
  • Numerical integration for real world physics
  • Advanced collision detection

And if that doesn’t get you excited, I don’t know what will! (And yes, maybe I should get out more…) It’s due out 1st December.

Interactive Digital Fireworks – new video!

The Brighton Unitarian Church

It seems like I’ve been promising to write this one up ever since November! And now I can finally reveal the official video of the event! Which gives me the perfect excuse to get around to this blog post. πŸ™‚

So it gives me great pleasure to present Pyro(technics) to the People – The Movie πŸ™‚

Pyro(technics) to the People was an massive interactive digital fireworks display that was here in Brighton last November 5th. (Which is Guy Fawkes Night for readers outside the UK). It was squeezed kicking and screaming into the world by my team at Plug-in Media, and it was made entirely in Flash.

Ever since seeing the awesome work with Graffiti Research Labs‘ (GRL) Laser Tag project, I’ve become utterly obsessed with the idea of projecting various things onto the sides of buildings.

And as you may have noticed, I like Flash particles. πŸ™‚ And over the last couple of years I’ve been toying with the idea of an interactive fireworks display. And I walked past the Brighton Unitarian Church pretty much every day. And I just found myself staring at it…

The Brighton Unitarian Church


So when Tara Solesbury (then of Wired Sussex) asked us if we had any ideas for the Brighton Digital Festival, it was the perfect time to tell her of my plans! Tara, being the one-woman tour-de-force that she is, set about making it happen; coming up with the catchy title, writing a super convincing art blurb that made me sound like an actual artist, and putting all the various and many different pieces in place for it to actually happen.


Thanks to the massive speed increases in Actionscript 3 it’s now possible to use Flash for this kind of ambitious project, where previously we would have had to use Processing or native code. But still, there was only about 2 weeks to go and a lot of unanswered questions…

Before we could do anything else, we had to make a nice firework effect. Using the Plug-in Media particle system, we created this :

Drag the slider down to increase the number of rockets.

In order to achieve the kind of numbers of particles we needed, we used only bitmap objects, drawn onto a big bitmap, which is much faster that moving around a whole load of sprites.

Once we got that working, of course we just didn't know what stuff would look like when it was projected onto this rather strangely shaped building! And we obviously couldn't just hoik our stuff down to the church and have a go! So the Plug-in Media team built a scale model. We were so busy my gorgeous fianceΓ© Jenny even helped out :

Building a model of the Unitarian Church

And thankfully, when we projected fireworks onto it, it looked kinda cool.

Cool practise projections

Motion detection

The motion detection and sensors were all done with a single video camera, plugged into the computer and picked up by Flash as a Camera object. We'd just take the current frame, invert it and overlay it over the last frame. Anything that was different between the frames would show up. Then we'd apply a threshold and use that to detect the changed pixels.

Here's an example of how it works :
Flash content available here
Drag the red detection area around to see the effect. And you'll need a web-cam otherwise it won't have a video feed to test!


Naturally the main fireworks Flash object (swf) took up the entire screen for the projector, and I needed to calibrate and control this from my laptop screen. So I had to make a secondary controller swf that communicated with the fireworks swf. It was a bit of a nightmare to program with the horrible LocalConnection object, but we managed to get it working in the end.

Me at the controls
Photo by Nic Serpell-Rand

The calibration tool allowed us to move the collision areas, adjust their sensitivity, and as a nice last minute touch, we could type messages that were then projected to the audience during the show.

Projector woes

Having seen how GRL did it, we thought we knew all about projectors. How hard can it be? Just get a big arse projector and point it at the building, right? Well it's a little more complicated than that. Wide lenses, zoom lenses, throw ratios, contrast ratios, power requirements, and of course the all important lumens brightness rating.

Thankfully, Tara had enlisted Mark Scarratt and, who have considerable experience in this type of large digital event. GRL were using a 5000 lumens Panasonic projector. But that wasn't going to be enough for us!

We asked XL Video about hiring one of their Barco projectors - an awesome 20,000 lumens! But rather frustratingly they were all booked out. (We later found out that Haque Research and Design were hogging 4 of them for their astonishing and beautiful Evoke installation at York Minster)

After discounting the Christie Roadie 25K lumens projector (it needs 3 phase power) Mark and his team hunted down a brand new Sanyo XF47 - the first in the UK and with a contrast ratio of 2000:1. You can't really tell from the picture, but it's HUGE! Just under a metre long in its cradle.

Oh and it costs over Β£1000 per day to hire. Eek!

Sanyo Projector


And of course what would fireworks be without the pops bangs and fizzes that usually occur? So we set up a mixer, and a couple of radio sets that transmitted the sound effects from the computer, across the road to a 16K sound system provided by Andy Mead and his company Firefly Solar.

The Future

We're already planning bigger and better things for version 2 that I can't really talk about. But keep an eye on the blog and I'll let you know. πŸ™‚

Blowing things up in Toronto

Having a fantastic time here in Toronto, although in a supreme display of poor planning my session is at 9am this morning! Never fear! We shall fight the hangovers from the awesome party last night (thanks Influxis) and produce more crazy particle effects!

As ever, bring your laptop and join in with the fun... download the source files here.

[UPDATE] Wow! What an amazing turnout, thanks so much for the support, especially at 9am!

Particle tutorial now on

After the Computer Arts article last month, you can now see my full particle presentation over on [sorry, no longer available]. It’s a screen-cast of my presentation at Flashforward in Boston last September. So if you want to know how to make Flash smoke, sparks, or blow things up, this is the best place to go!

You can download the actual files from this session here, or get the latest updated versions here. [sorry, no longer available]
I’ll be slowly phasing this presentation out in favour of more complex particle effects and Papervision3D, so this is a great place to see this session.

And, as ever, let me know what you think!