PDA

View Full Version : [AS3] Monster AI in Dungeons


Ciubhran
09-15-2009, 10:44 PM
Trying to add some AI to my game.

So far the enemy has a Detection Range (Aggro Range).

If the Hero enters this range, and the enemy has sight of him (a line that is drawn from Enemy to Hero, and if it collides with walls, then the enemy does not have sight of the Hero) then the enemy will charge and attack.

Then when the player goes out of line of sight, the enemy runs back to its original position.

This all works great, but it is easily exploitable as you can just run around corners and the enemy will reset, which is not what I want.

So the bottom-line is: Does anyone have any good examples of how to make computer AI that runs around walls and/or other ways of making some form of pathfinding AI that the enemy follows so he doesn't run into walls as easily and will ignore the walls if the collision is "small", like when you run around the corner.

There are thousands of games with this AI, I am hoping to find someone here who has experience of this kind of enemy AI.

I don't want the AI so dumb that is forgets what it is doing just because I run around a corner.

rrh
09-15-2009, 11:27 PM
General pathfinding is A Star.

But you're trying to make monsters with imperfect knowledge, and I think there's maybe a simpler method. The first thing I'd try is if the monster can see you, he will store the location that you are when he sees you. If he can't see you, he will chase the last location where he saw you. Only if he reaches the last location he saw you and can't see you will he return to his original position.

If you want to make the monster a little more persistent, then you could also store the direction from him to where he saw you and have him continue past where he last saw you in that direction until he hits a wall or a fork in the road (depending upon how you store your maze data)

Ciubhran
09-15-2009, 11:46 PM
General pathfinding is A Star.

But you're trying to make monsters with imperfect knowledge, and I think there's maybe a simpler method. The first thing I'd try is if the monster can see you, he will store the location that you are when he sees you. If he can't see you, he will chase the last location where he saw you. Only if he reaches the last location he saw you and can't see you will he return to his original position.

If you want to make the monster a little more persistent, then you could also store the direction from him to where he saw you and have him continue past where he last saw you in that direction until he hits a wall or a fork in the road (depending upon how you store your maze data)

I like the idea of chasing points, and upon arrival decide what should happen next (unless he comes real close to the target before reaching his point, which is when he will derail from his path).

But how would you go about using A* when you don't work with tiles?

BerggreenDK
09-21-2009, 12:56 AM
I like the idea of chasing points, and upon arrival decide what should happen next (unless he comes real close to the target before reaching his point, which is when he will derail from his path).

But how would you go about using A* when you don't work with tiles?

I believe it dependes on your maze data structure.

In old 3D games like Doom/Quake etc, the walls etc. were precalculated into "areas" and then you could pass from area to area as far as I recall.

When you have such a datastructure, then you can do some "sort" of Star-algoritm as those areas will have to be connected too. You could also add "movement speed/length" to the area - like ... water is slower/takes longer etc... that way your "monster GPS" can find the most suitable way. But I think "visual" contact is important too. Its annoying when a monster can "sense" you through a wall.