Game Development Community

dev|Pro Game Development Curriculum

Horrible Little Flying Things

by Daniel Buckmaster · 09/10/2009 (12:00 am) · 13 comments

I even made a video! I guess that's kind of mandatory, butI'm proud of it all the same. I was going to go as far as making a voiceover to tell you what's going on, but I just realised I don't have a mic, so you'll have to do without my lovely bass tones, and read the explanation instead.


My swarm class was inspired by the old fxSwarm resource, which I intended to use as a base and modify - but I ended up writing my own class from scratch, because I wanted datablocks. I also use a different method to update the swarm particles - instead of truly swarming, the particles just rattle around inside their boundary shape. I'm hoping this means the calculations for updating particles are simpler and less costly, but I realy don't know - I will be doing more detailed performance testing when the class is finalised, and I can go ahead and optimise the update routine.

There are three shapes planned, Box, Sphere and Cylinder. You can see two of them in the video, Box and Sphere. I haven't finalised the boundary calculations for the cylinder type yet, so that's not in there. You can see different quad textures used, and possibly you can tell that the quads can be set to different sizes in different swarms.

I couldn't resist doing something huge, so that last swarm is a huge Box with 5,000 particles in it. I'm going to do some more stress testing of that sort, and see how many particles I can add before I start to get performance problems :P.

There's one more issue I need to fix before adding the remaining features - the swarms really don't like to be rotated. I rotated that huge swarm in the editor, and particles went flying in all directions, as if they no longer felt like obeying the boundary rules for some reason.

Additional features planned are adding sound to the swarm, doing damage to players inside a swarm, and anything else I can think ofthat I really want to add.

About the author

Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!


#1
09/10/2009 (12:16 am)
For Be The Dinosaur we also started with the fxSwarm class and in the end wrote our own.

We ended up with a threaded swarm AI class that would react to players either moving towards them or away and would work as either fish, birds, turtles, crabs, etc.

It was neat stuff.
#2
09/10/2009 (12:24 am)
Nice job Daniel! Wish I had known about that resource, I would have put it to use in my recent project.

As it was, I ended up just doing and animated particle that works well as a single bug moth thing, but the swarm would have been great.
#3
09/10/2009 (12:50 am)
Whenever I see swarm stuff I'm suddenly drawn back to way too much time spent playing Quake II and the fly swarms over various dead things.

I also used the fxSwarm resource once...long ago when I actually worked on making games myself...but I didn't go much further than the resource since that was just at the limit of my code knowledge...=P

Looking pretty cool.


[small hijack]
@Todd,
Why haven't I seen any pimpage of that pack here? That Enchanted Forest Environment Pack is obscene it is so nice! I think I might just go to bed early. =)
[/small hijack]
#4
09/10/2009 (1:30 am)
Very cool!

I remember playing with that fxSwarm resource a while back and having so many ideas...

Having the swarm react to the player would be great. Damage? Now that sounds like fun :D
#5
09/10/2009 (2:18 am)
@ Tom and Michael, Reaction to the player would be great to sale the impression, just having them disperse when the player enters the volume area, or swarm around the player when they enter would be cool.

@ Alan, Thanks :O) check my blog post for details, don't want to hijack the post.
#6
09/10/2009 (3:33 am)
Thanks for all the comments, guys!

Tom - I did want to use this for things like fish and birds, but in the end I decided to separate that out into a 'flock' class, which will render shapes, and feature algorithms designed to only support a smaller number of 'particles'.

Todd - hijack away, I was going to ask about that pack as well! It looks brilliant!

Alan - my memories of swarms are from Thief...

Michael - player reactions are something I'll definitely look into, it'd be simple to add a repulsion/attraction force to the particles, centred around a certain point in the swarm. If I'm already detecting objects to do damage, then it'd be easy to make them swarm around that point/try to avoid it.

I also forgot to mention in the blog that I'm planning to add movement of the swarm as a whole, in a very simple AIPlayer-style 'setMoveDestination' sort of way, so you can get swarms that chase the player, or meander around or whatever.
#7
09/10/2009 (4:25 am)
Nice Daniel, looks very cool.

I too have memories of the buzzing flies from Quake 2 ... *sigh* ... I am getting old. :)

I take it from your comments that you will be releasing this as a Resource. :)
#8
09/10/2009 (7:23 am)
Very cool stuff there Daniel.
#9
09/10/2009 (2:49 pm)
Quote:so you can get swarms that chase the player, or meander around or whatever.


Nice!, especially if they can inflict damage as well.

I wonder if this could be extended to make a firefly type effect as well, maybe by putting a single slightly flickering light at the center of the swarm. Then you could have friendly swarms that light your way through a darkened area of a level, such as an unlit cave or tunnel system.

#10
09/10/2009 (6:23 pm)
Very nice!
#11
09/10/2009 (11:34 pm)
A trick to optimizing things like that, if they use sin, cos, sqrt, or other costly operations, is to cache the outputs for conceivable inputs to the operation in an array, then just interpolate the values when they are needed. I believe precipitation uses something like that.
#12
09/11/2009 (8:43 am)
NovoGeek - this will be resourcified eventually. Probably later rather than sooner, though, as part of the code pack I'm calling Horrible Places.

Adrian - light is a good idea. Taken on board ;)

Dan - Thanks for the tip. I don't have anything like that for the moment, just vector length calcs (I use length squared when possible for comparisons). I don't know if itd be feasible to cache results for length calcs...?
#13
09/12/2009 (11:16 pm)
Can't wait to see more "Horrible Places" info and features, In your original blog I really liked the style you planned on going with it!