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?
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
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).
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. 🙂
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.
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!
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…
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 :
And thankfully, when we projected fireworks onto it, it looked kinda cool.
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.
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.
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 brightonart.tv, 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!
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!
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.
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. 🙂
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!
After the Computer Arts article last month, you can now see my full particle presentation over on lynda.com [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.