Advertisement

Top-Down Herd/Flocking AI ?

Started by May 22, 2005 11:23 AM
3 comments, last by mwtb 19 years, 5 months ago
Recently, I was looking at making a single-player RPG, with some weird AI stuff (herding, influence, etc.) in it, and yesterday, I was considering herding. Anyway, what my idea is is this: Every n ticks, a herd AI is called. It considers the basic layout of the area (Which is composed of data it's members have reported since the last iteration, such as "Attacked", "Cut off", or "Position is" if nothing else happened. [This is used to determine the approximate position]) and sets a command struct up with a VERY basic command, such as "Move NNW", "Attack", or "Scatter", though nothing specific. Each time a NPC who has the herd flag set wants to do something, they look at the herd struct they belong to, read the command, and react to it. The rules for belonging to a herd are very simple, and are evaluated before movement: A: If two NPC's with the herding flag set are within 2m of each other, the one from the smaller herd will join the larger herd. If neither belongs to a herd, the first evaluated will create a new herd, which the other will join. If one has no herd, it will join the other's herd. For any case, every other NPC within the 2m will be evaluated before it tries to join or form a herd. B: If an NPC is 8m from it's herd, it cuts all relation to it, and evaluates A again. (Each NPC will always try to stay within 5m of it's herd, so this shouldn't pose a problem.) Now, is there any way I could make this more effective? Right now, I'm not particularly keen on eating through too much CPU. I suppose I could also use attraction between the entities, but that is slow ofr movement (though easier on CPU), and causes them to stay in approx. the same place, and move quite slowly, as opposed to a herd, where all members do approx. the same thing, and aren't afraid to move. Thanks in advance, I really appreciate it.
I'm curious as to why you want to do this "top-down" when the mechanisms for the behaviour as "bottom-up" are fairly well understood and documented? Do you have performance concerns or control concerns?
Advertisement
I think that the cpu requirements will be quite modest for this sort of thing, especially if you use a spatial data structure to reduce the number of members you have to compare against others.
Thanks. I've been worried about CPU being at a premium, and trying to get the most complex responses, for the least CPU usage... at least theoretically.

As mentioned above, the major expense in terms of CPU for bottom-up is the influence checking and this can be dramatically reduced by using sensible data structures, or may well not be an issue at all if you have small herds.

This topic is closed to new replies.

Advertisement