Game Development Community

dev|Pro Game Development Curriculum

fxSwarm

by Dylan Sale · 05/02/2003 (1:16 pm) · 22 comments

Download Code File

This is an object that makes swarm particles (not the same as other particles) move in a swarm. There are many options that can be changed to affect how the swarm moves. It was based on Melvs fxRenderObject.

The swarm can be told to go somewhere, follow itself (swarm around) or it can be paused.

Ive implemented a VERY simple optimisation thingy that will add or remove particles based on a target fps that the user inputs, this is useful as all the particle vector calculations are done in the render function which means that the particles will calculate more and move more if you have a faster system, so this system will add more particles to make it run smoothly (a sort of primitive frame limiter).

It does not interact with anything else at this time, and the particle positions are not broadcast over the network, so each client will probably have a different version, so it is not very useful for games that need everything to be synchronous.

It can be given a texture that is then used to render the particles as billboards, but if none is given, they are rendered as points.



It was origionally started as an interest and lead to what you see now. It could be used as a swarm of flies over a carcas or as a swarm of bees that moves around a flowery meadow. Its up to you.

There is a much more detailed readme in the zip file.
Page «Previous 1 2
#1
05/02/2003 (1:20 pm)
Sounds cool... So this is a server object? and it works correctly over the network? I've thought about playing with something similar myself and had definitely been thinking along the same lines... ie. not synchronizing the clients, but only transmitting the swarm's target position and other relevant data.
#2
05/02/2003 (1:46 pm)
Tim,

I do not think it is network aware as quoted from above:

Quote:
It does not interact with anything else at this time, and the particle positions are not broadcast over the network, so each client will probably have a different version, so it is not very useful for games that need everything to be synchronous.

-Ron
#3
05/02/2003 (2:13 pm)
In the quote he's talking about individual particle positions, which I don't think you'd ever want to transmit over the network. If the swarm's target position is set on the server (and transmitted to the clients), then the clients would generally have the same swarm effect, though the individual particles may be different.
#4
05/02/2003 (5:04 pm)
Tim,

Sorry about that

I now follow the thread more clearly after reading it again without 2 screaming kids in my ear begging to go to Chucky Cheeses

-Ron
#5
05/02/2003 (10:16 pm)
wow, the swarms of flies over dead bodies was cool in quake2.
#6
05/03/2003 (3:26 am)
Dylan,

I know it probably doesn't matter in this case that the particle positions are not the same on all clients but I was wondering if you've considered a neat trick that I used in the shape replicator which is to pass a seed value to the clients and then use that to seed the random number generator used to create the particle positions.

That's how the shapes on the replicator are all located in the same position on all the clients without transmitting the individual positions.

Just thought I'd mention it.

- Melv.
#7
05/03/2003 (6:40 am)
Melv,


That is an excellent idea! heck I might nab this snippet and play with it a bit :)

-Ron
#8
05/03/2003 (6:42 am)
@Tim Gift
Thanks ;) I thought it was cool,and others might find it useful so I posted it here. At the moment the target position is transmitted, as well as the weights and other variables, so each client should be roughly similar. But there is SO much that could be fixed and enhanced, really this is just a prototype. I just wanted something to work on in my Uni break so I did this. I probably wont have time to update it much, so if you or anyone want to make it better then by all means go ahead :).

@Melv, yes I thought of that, but I made this as a SceneObject and all the velocity calculations of the swarm are done in the render function, therefore if you have a better computer you will do more calculations per second and so your swarm will quickly un-synch. (I was trying to find a way to overcome this, but sadly I ran out of time, so if anybody wants something to do ;) ).

Thanks for the feedback, its good to know I can give something back :D.

Dylan

PS, the target position is the swarm object's current position, so by moving the swarm object you move the swarm's target. (only is self swarming is turned off by using the moveTo() function)
#9
05/03/2003 (6:55 am)
Also, I must say that I spent only about an hour researching particle swarm dynamics so the model I used is not the best, but it works. Mostly I just played with the variables until it seemed "right". However, I was working on about a 100x scale to the size of the player ;). Since then I have been able to tweak the weights to get it having the feeling of buzzing flies on a player scale, it just takes a bit of time, maybe I could add datablock support (upgrade it to a GameBase object), then have different datablocks for different effects, ie bees, birds, flies, etc.

But this is just be thinking out loud, I may never get around to it.
#10
05/03/2003 (7:20 am)
Hmm I just realized that there has been a few resources on Boids and swarms here. These could have come in handy... I might have to do a quick update.
#11
05/04/2003 (7:18 am)
Fascinating, what model did you use for the swam dynamics?
#12
05/04/2003 (9:48 am)
There's a swarming article in AI Wisdom 1 btw if anyone's interested.

Pretty simple calc's overall :) not up to boids, but reasonable enough.

Phil.
#13
05/05/2003 (9:41 pm)
I dont know what model I used. I just made it ;) Im sure theres tons of things that could be optimised in it though.
#14
07/30/2003 (8:07 pm)
Does this have built in support for transparent pngs? I couldnt get any to work and that would be key. Also, the swarm seems to move REALLY fast even with the limiter (forgot what its called right now, the last field in the editor) on... I'm gonna take a closer look at it.

Thanks,

-s
#15
07/30/2003 (8:14 pm)
It should use pngs. I dont know why it would be.. are their dimensions powers of 2? As for the fast movement.. yeah, the default settings I made when there was no terrain or any other objects in my level so i had nothing to judge the size of it.. so it works smoothly when you make the size of it huge. To get it working on a smaller scale you really need to play around with the weights and stuff. Then if you still cant get it to work, try the limiter, but that limiter is pretty crap, so id try and get it working with weights. also, try addin/removing particles.

I should really fix this. It is pretty dodgy, but it was really only a prototype when I ran out of time.
#16
05/08/2004 (6:42 am)
Hi Dylan, nice work. I played with your code a bit and managed to optimize it to reach 25 Fps with 4 swarms of 1000 particles each (4000 particles on screen). Considering that I was getting same output with 150 particles it leave lot of space to add some AI to the swarm. I like to have the particles do more "thinking" so I will play a bit more with the code. I will post a complement resource if ever I get something done :)

If somebody like to have the optimized source then send me an e-mail I will gladly send the code around.
#17
05/09/2004 (9:26 pm)
Good to know that someone found a use for it ;)
#18
11/06/2004 (4:34 pm)
This tweak adds a Tempo field you can adjust in the editor.

Makes it much easier to control swarm movement without changing size, weights etc.

Might be inefficient, but it makes this resource more flexible as a design element.


In fxSwarm.h
add: F32 mTempo;




In fxSwarm.cc

after: mNumParticles = 150;
add: mTempo = 25.0f;


Around Line 336:

replace:
// if(ElapsedTime >= 1.0f/30.0f){

with:
if(ElapsedTime >= 1.0f/mTempo){

and uncomment the } a few lines down.




After:
addField( "SelfOptimize", TypeS32, Offset( mSelfOptimize, fxSwarmObject ) );
Add:
addField( "Tempo", TypeF32, Offset( mTempo, fxSwarmObject ) );



After:
stream->write(mSelfOptimize);
Add:
stream->write(mTempo);


After:
stream->read(&mSelfOptimize);
Add:
stream->read(&mTempo);
#19
11/06/2004 (4:52 pm)
Cool. Yeah I think I was going to do something like that but never got it finished. Thanks :D
#20
11/28/2004 (4:31 pm)
Cool resource
Page «Previous 1 2