News:

If you need instructions on how to get through the hotels, check out the enclosed instruction book.

Main Menu

AS crowd ai

Farted by AmberArachnidClock, March 28, 2010, 05:15:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AmberArachnidClock

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?

SageClock

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/

AmberArachnidClock

Thanks I'll look into both of those!

SpongeClock SquarePants

yeah, pretty much go with what cable said. Would be fun to try the box2d solution btw.