AI routine concept

Posted by Onyx on Oct. 9, 2006, 4:31 p.m.

I made no real progress with my sneaker. I didn't have egnouh free time lately. I should start on AI but I don't want to start it and then work on it throught a whole week. I mean, I probably will work on it for a whole week, but I want to make all the basics in one go, and then go from there. It will not be too hard to make a basic engine. Not that it will be easy, but I did most of it before and lost source to it, but atleast now I know exactly what I'm doing,

Now, I would like some opinions on the way I constructed my AI. This method is pretty CPU-heavy, but I think It can't get much better. The basic "follow player aroud" stuff is simple, nothing special here. Now, when enemy collides (or is about to collide) a solid object he does the following:

First, a loop which searches for all the corners of solid object is executed. I must point out that "solid obkect" won't allways be a single object and won't be allways rectangular. I does this by following the outlines of object in counter-clockwise direction. Coordinates of each corner are then saved to an array.

Second, it marks 4 specific points:

1) starting from index 0, it marks the last point it can "see"

2) increasing the index it marks the first point from which player can be "seen"

3) same as the above, but this time it's the last point

4) same as one but this time it's the first point it finds

When I say "see" I mean there's no obstrucrions in way (collision_line returns -1)

Third, as the movement is 8-directional, he can skip some points, e.g. if there's a corner like this _| and enemy moves from that upper-right corner he doesn't allways have to go to that inside corner, only if there's an obstruction in a way when moving diagonaly. So, it finds these points and marks them as neglitable.

Last, it now calculates lengths of two paths: if he goes clockwise and if he goes counter-clockwise. He chooses the shorter one and follows it.

Now, I could make solid objects calculate corners themselves in create event, but there are some issues:

1) it would have to be global variables (arrays)

2) once enemy collides, it must first know which array to use, so I would probably have to store instance ids too

Now, what do you think, is this system any good? How to improve it?

Also, I would like enemies to collaborate, so they don't all choose the same path. I don't want it random either. I will have to find a way to make them look for other enemies as well. I think i'll make some kind of simple checking, like if there's an enemy right of him allready he'll take the left path. But that's an issue for another blog.

Comments

Acid 17 years, 7 months ago

That system seems like it will work well, but we have yet to see it implemented before we jump to any conclusions on how it can be improved.

Onyx 17 years, 7 months ago

Well, it worked before. I need to rewrite it thought.

ultim8p00 17 years, 7 months ago

I made a tds a long time ago and it was very effective. I didn't know about collision_line yet so I used a sprite that was as long as the view. Then I had the enemy move in a random direction and Had the line originate from him. Then, the line would point in whatever direction the enemy was moving. The line object itself was sensible to the player and when the player got way too cloose or if it collided with the player, it would alert the enemy about the player's presence and then the enemy would "lock" on the player and then try to chase the player if he was trying to get away or back off ih he got close, all this while attacking the player. The player moved faster than the enemy so it was possible to get away. It had its limitations, mainly the fact that you could not sneak up behind the enemy to do stealth kills. I modified it using the collision_line function and then the enemy would ignore the player if the line collided with a solid

Onyx 17 years, 7 months ago

Simply following the player around is not a problem at all: enemy checks if player is close egnouh to be seen. If he is, it checks if player is inside his view cone (direction+/-45°). Then I use collision_line to check for solid objects. If there are none he's alerted. Then he just checks for direction of player and follows him (considering 8-directional limitations offcourse) Due to game mechanics it's impossible to really get away: all enemies chase you at the same time, only way to escape is to remain hidden long egnouh. But that's piece of cake ;)