For my AI, I do what is basically a LOS routine for each monster. It looks at a
square centered on the monster with a width of 2 time that monster's perception.
If there is no monster on that square, the search continues with the next
square. Other wise it runs another check. This check makes sure that this
square is within the rane of the monster's sight. This is easily accomplished
by checking if the sum of the x and y differences squared are less than the
perception squared ((dx*dx)+(dy*dy)<(per*per)). After those checks, it then
draws a line between the monster and the one just found. The line is then
traced to make sure that there are no obsticles in the way. If there are not,
it notes the point next to the AI monster, otherwise it continues the search.
Now, if these checks reveal the there is indeed a monster that can be seen by
the monster that the AI is applied to, then we find the AI monster's attraction
to that monster. (BTW, you are considered a monster.) This can be affected by
things like species hate, fear, etc. I call this affinity. It can be negative.
The affinity will be subtracted by the distance away the monster is. (this is
simply whichever is greater: dx or dy). This affinty is then added to an array
depending which direction the monster is in (remember the point that was
stored?). The search then continues.
After the search is over, the directions and their affities are evaluated, and
the monster moves in the direction most appealing to it.
<snip look for monsters in LOS>
> Now, if these checks reveal the there is indeed a monster that can be seen by
> the monster that the AI is applied to, then we find the AI monster's attraction
> to that monster. (BTW, you are considered a monster.) This can be affected by
> things like species hate, fear, etc. I call this affinity. It can be negative.
> The affinity will be subtracted by the distance away the monster is. (this is
> simply whichever is greater: dx or dy). This affinty is then added to an array
> depending which direction the monster is in (remember the point that was
> stored?). The search then continues.
>
> After the search is over, the directions and their affities are evaluated, and
> the monster moves in the direction most appealing to it.
This is a nice idea. It's very similar to an autonomous robots technique
for obstacle avoidance called 'potential fields'. This treats every
obstacle in your neighbourhood (possibly the world) as a potential source,
with a sign. So you are attracted to unlike potentials and repelled from
like potentials. So then you work out the vector sum of all this
attraction and repulsion, and move in the direction of the vector. It's
real fast and pretty simple.
One problem is that it's definitely subject to getting stuck - you can
easily be in a position where you don't move at all (when attraction and
repulsion are balanced in 2D). But to counter this you can probably add a
random factor which ensures that you always move.
Yeah, it's a really good idea.
(It plays a part in my multiple levels of AI principle outlined
elsewhere.)
later,
Dave Slutzkin.