Sign in to follow this  
captain_crunch

Group and herd movement

Recommended Posts

I am implementing group movement for humans, and herd movement for animals in my game - I would like to create the functionality to cover both cases at once. Flocking techniques seem inappropriate. They are more suited for swimming/flying movement, right? I don't want the entities to jitter and get stuck in collisions either. So my idea is to use the formation movement technique from Company of Heroes described in AI Wisdon 6. In this, each group member is assigned a position to move to. But insted of sharp v- and column formations, I need a nice-looking clustering of the entities. Can anyone suggest an algorithm for producing positions for each entity? Preferably, it should take account of the other group members when new ones join. The group will get out of shape at some point, so I think it should be able to reform naturally, also. Do you think this kind of top-down assignment can be made to look natural, or is it the wrong approach?

Share this post


Link to post
Share on other sites
Maybe some kind of spiral pattern? First person is the origin, second person is placed at a specific distance from the first. After that each one is place at that distance from origin and the previous person until that "level" is complete. So seven would be the center person with six people around them forming a hexagon. I'm not entirely sure what the pattern is after that, but you can keep doing this and build a structure out of equilateral triangles that resembles a hexagon at every level. If you offset each position a little bit when you calculate it they should look pretty good. Sorry this isn't an actual algorithm, I just drew it out on paper.
I guess you could just use a normal spiral, but I'm not entirely sure of the math behind that.

Share this post


Link to post
Share on other sites
Yes, it sounds like it might work.

I also want entities joining the group to be assigned a position along the edge of the cluster nearest to where they are coming from.

When the herd starts moving it should become elongated rather than circular. I'm thinking this can be done by designating the entity at the edge as the leader. When the herd starts up, the members will be delayed an amount of time in proportion to their distance from the leader. They must be prevented from speeding up to reach their actual positions though, or the herd will become circular again...

Share this post


Link to post
Share on other sites
Maybe you could assign a position and velocity to the herd itself, and each member could have a velocity (and, of course, position) that is a function of the herd's position and velocity. Members that are nearest to the "forward edge" would have their velocities weighted most heavily towards the actual herd velocity (to reflect a "leadership" role among any members near the front at any given time). Other members could meander any which way at any given time, but if they stray too far from the herd they will gravitate back toward the herd's center. I suppose another side effect of this is that the trailing edge would taper off like you want.

You would have to tinker around and come up with some good heuristic functions, but I think this could generate nice results.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this