- Home /
Objects 'Clumping' problem
Hi,
I have a scenario where there are about 50 to 100 objects all following one target. All objects have rigid-bodies, non-trigger colliders, and using physics based movement.
After chasing their target for a while they end up being very close to each other and start to clump. As a result they all start bumping into each other. This starts to slow the game down, so I am guessing it's down to all the excess physics interaction going on between them.
So, I am looking for suggestions on the best route to avoid them 'clumping' together. Is there a traditional method dealing with this type of scenario etc?
Thanks!
Paul
Answer by Fattie · May 12, 2013 at 07:43 AM
This is a super-difficiult and super-cool problem.
Here's one quick solution that can sometimes help.
Your target is TT right.
Make an imaginary sphere around TT. Well .. imagine it :)
Take a number NN and a radius RR. You will tune these values later. At first try say "20" and "15 meters".
For NN times, make a new marker (I mean empty game object) called TT1, TT2 etc.
In fact position those randomly within a sphere of radius RR around TT.
Using gizmo or something add a dot for all these for your benefit. Note that as the spaceship at TT actually moves through space, all these "secondary targets" will follow - right? As the spaceship pitches, rolls and yaws this "cloud" of TTn will sort of swing around in space. OK?
Now regarding your 50-100 chasers.
In fact, don't make them chase TT. Make each one of them randomly choose one of the TTn, and chase that.
Again, test this over and over with different values of NN and RR. And instead of "a sphere" the random TTn points could be on (say) a halfsphere facing forward, or on a small plane normal to the forward of the TT-spaceship.
Further, you may want to randomly change the TTn ("every four seconds" or something) which each chaser is looking at, and further you may change to TT itself when within a certain distance, perhaps. (Naturally this depends entirely on what you're doing and why.)
I hope this approach helps. It is vastly easier if you post a screen shot to give an idea of the scales involved, etc.
"This is a super-difficiult and super-cool problem" hehe yeah I always seem to end up with those! That's an interesting idea Fattie, I am considering using a flocking approach to controlling them, so for example find the nearest attacker to me and make it the flock lead. I think I will play with both today and see how it goes. If no-one else replies to this with other ideas, I'll mark it as an answer.
another simple idea is this.
imagine you are Chase38. so "now" mark the point where the target is. call that currentTarget. Chase towards that currentTarget.
ie, the Spaceship will move on from currentTarget, but you chase to currentTarget.
Next, take a RANDO$$anonymous$$ time, between about 1 and 3 seconds.
after that random time, reset currentTarget to where the spaceship is now.
Now the key is, each of the 50 flock members do that individually, ie they all random choose, each time, the time I describe.
this is another very simple approach that can work. they will all have fun and move around, without just crashing together
So particle and insect control systems often don't consider inter agent collision at all - which is one possibility. Another is to use a different method to keep them apart, turn off their inter-collision physics and ins$$anonymous$$d use something like writing position with some degree of rounding into a sparse dictionary - if you find something else already there, move the new item in the opposite direction to their current positions and keep doing that until it is in an unoccupied space. The trick then is to Lerp to this new position.
Thanks guys! Loads to be going on with here. I am currently working my way through all my scripts so they use #pragma strict and variable caching, when I am done I will have a go.
Funny how often in life we have to attend to extremely modest concerns before dealing with huge philosophical issues.