Clock Crew

Arts & Leisure => Gaming & Technology => Topic farted by: AmberArachnidClock on March 28, 2010, 05:15:59 PM

Title: AS crowd ai
Post by: AmberArachnidClock on March 28, 2010, 05:15:59 PM
I am trying to code a crowd of people in flash wandering around aimlessly. I am having trouble making it so each person occupies their own space and wont overlap each other. Right now they wander around, and walk right through each other. I am using actionscript 2. Does anyone have any pointers for how to do this?
Title: AS crowd ai
Post by: SageClock on March 28, 2010, 07:23:45 PM
crowd avoidance A.I. such a fun problem.

basically each person needs to be aware of the position of all the people nearest to them and choose a direction that points away from the closest ones, roughly.

you could brute force it, just check to see if anyone is overlapping anyone else, and if they are, push that person out in the opposite direction as the direction they're moving in until they no longer overlap, but if you have too many people this becomes very slow.

so you want to rule out whole chunks of people without even manually testing them. that's where the closest points algorithm comes in (there are other possibilities as well, but closest points is pretty good). treat each person as a point, and for each point, find its closest pair (and maybe anything within a certain range) and test that. if you use closest points, go with the planar method. brute force will be quite slow (unless you have a small number of people; if so, just do that, it'll be easier)

http://en.wikipedia.org/wiki/Closest_pair_of_points_problem

another alternative I just thought of is that there are physics libraries in flash; you could possibly just make each person a circle (as far as the physics engine is concerned) and turn gravity off of it, and let the physics engine handle collisions for you. box2d is the most common one.

http://www.box2dflash.org/
Title: AS crowd ai
Post by: AmberArachnidClock on March 28, 2010, 11:20:15 PM
Thanks I'll look into both of those!
Title: AS crowd ai
Post by: SpongeClock SquarePants on March 29, 2010, 09:07:34 AM
yeah, pretty much go with what cable said. Would be fun to try the box2d solution btw.