Just some stuff about front-end development

Back

Fun with anti gravity

Some time ago, I needed a simple crowd algorithm for a project of mine. In that project there was a bunch of entities, which were moving towards a common target. Everything was alright until those entities were close to the target and each other - every entity was placed at the target at the same point. I've tried to implement some collision detection for every entity, so if one entity detected that it is colliding with another one, it would stop moving and wait for the second entity to go away. But, when there would be multiple entities in proximity - then almost everyone would wait for everyone.

The solution for a simple, almost dumb crowd simulation was very close. Every entity, instead of stopping and waiting, should apply a reverse force which would depend on the proximity to a near entity. That approach is the opposite effect to gravity - anti gravity.

The result of this algorithm can be seen above, with some presets for particle behaviors from a “crowd”, “jelly” to “bacteria”. Such a simple solution can create a great range of possibilities. Of course this is not near a full blown crowd simulation with advanced agent AI, but for my small project, the anti gravity did a great job.

comments powered by Disqus