I'm trying to create a simple but effective blend of Ai effects to make enemies behave with a little more wisdom.
It already has a very nice line-of-sight system (to check when enemies can see you), and everything else fits around that.
Currently they're using a little method I've called Last-Known-Pursuit AI. All it does is record the X/Y coordinates of the player in the alterable values of the enemy that sees him. Every time an enemy spots the player, that enemy updates his log of the player's position.
If he loses sight of the player, he doesn't lose interest. Instead, he runs towards the place where he last saw the player (chasing after the recorded X/Y coordinates instead of the player object). The assumption is that from that position, he may still be able to see the player (and thereby continue the chase).
At the moment, the enemy loses interest if he gets to the recorded X/Y location and the player is still not visible (e.g.: You've run down a corridor and hidden in a little alcove).
What I want to add are a few 'search' routines to follow this, so that instead of losing interest when they can't see you, they start to search the immediate area. The answer's probably quite simple.
What do you think?
A few rough possibilities:
- The enemy records not only the position you were in last time he saw you, but also the direction you were running. This way, when you disappear around a corner, the enemy'll have a rough idea of what way to run and look (this is especially useful at crossroads where you could have gone in one of many paths).
- Level-specific AI. This would be harder to do, but more realistic. You code some basic behaviours uniquely into each level, to reflect the fact that guards will know more about the area than you do. This could involve using Zones. E.g. The player is seen entering a zone which the guards know has only one exit. So they automatically block off the only exit and start searching that zone.
Perhaps there could be little active objects in each corridor giving strategy hints. For example, suppose there's a long corridor with a room at the nearest end and no others for a long way. The enemy chases the player around the corner and lo! He's vanished!!
It's logical that the player can't have vanished. He must still be nearby. The little hinter object tells the enemy that he should check the room, since it's the only place someone could hide.
Maybe you could do some kind of check for nearby disturbances, like if you run away and knock over a bin they'll hear this and try to find you. Same with footprints.
As for the level-specific thing, you could have areas that are more likely to be broken into on the priority list of places to search. For example, a corridor the player has just gone down has 2 rooms, one with nothing in and one with a computer disk in, obviously the player wants the security disk, so the enemy should look in that room. Now clever players won't always go for the plan A route now will they?
Peblo Custom ratings must be 50 characters or less
Registered 05/07/2002
Points 185
14th January, 2006 at 21:40:05 -
Have an event for when the player goes out of sight, it drops an invisible object facing the direction that he was, so that when the enemey collides with it, it knows which direction the player went.
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath
Yeah I was thinking that (although I'd store the data in alterable values, since I'm already using that for the X/Y coordinates).
Noodle: Good idea - perhaps not with knocking bins over, but certainly navigating to gunshots or hearing doors open/close/slam. The difficulty there is pathfinding so that the enemy knows which area the sound is from, and how to get there.
There must be some logical methods I'm missing.
Actually, I just had an interesting pathfinding idea...
191 / 9999 * 7 + 191 * 7
Peblo Custom ratings must be 50 characters or less
Registered 05/07/2002
Points 185
14th January, 2006 at 22:23:17 -
Pathfinding extension? You could place a series of checkpoints around corners and stuff so the enemies can find their way around by looking to the next checkpoint on their way to the sound.
Edited by the Author.
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath
That's what I'm thinking (the checkpoints/nodes idea). I was planning on giving each one a code to identify how you get to it, something like ##/##/##/##, where each ## is the ID number of the next node to go to. Imagine them like folders on a hard disk. E.g:
The player is at 0/1/8/3/6/24/12
The enemy is at 0/1/8/3/6/19/16/14/21/11
The player's nearest node is 12. The enemy's nearest node is 11.
Node 0 is a central point in the map, such as a lobby or corridor from which all other paths come out.
This information tells us that the enemy and the player are both on paths that branch off from Node 6. So the enemy must retrace his steps back to that node, by first going to node 11, then node 21, then node 14, then 16, then 19, and finally node 6.
He's come to where their paths converge, so he can now start climbing up the player's path. He's already at node 6, so he advances to the next one - node 24 - and then to node 12. Now he should be close enough to attack the player.
See what I mean? It's like a big tree of folders. Downside is that it's complicated, LOL!
The method I have at the moment is that you have to place the nodes at any junctions or corners in the map, and then have some kind of editor to assign them their codes (which will be stored in a list object or array).
191 / 9999 * 7 + 191 * 7
Peblo Custom ratings must be 50 characters or less
Registered 05/07/2002
Points 185
15th January, 2006 at 00:18:39 -
Of course with that method, the enemy will magically know where you are at all times, and the game will become pacman with bullets or something. Unless you tell the enemy when to stop (which then theres the question of getting him back to his post), he'll just keep chasing the player, no matter how stealthy or tricky he was being.
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath
It is pointless if he knows which way you went when you changed, I think you should log the direction you last saw him going and then he will stop, look around and then choose a direction within 30 degrees of the direction you were last seen going
Do you feel you are being... watched?
Peblo Custom ratings must be 50 characters or less
Registered 05/07/2002
Points 185
15th January, 2006 at 00:36:47 -
He knows what direction you were headed when you left his sight, but thats all he should know.
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath
I think looking around is good because it stops people from making a stealthy turn to the left, avoiding the line of sight because he searches the area for a suitable direction within his sight distance first
Peblo: The node idea doesn't run all the time, only when something happens like a noise. It lets the enemy navigate to the noise. It also gives them the ability to systematically search rooms by going to each one in turn to check if you're there.
Then there's the possibility that if enemies have radios, they can tell each other where the player is and all the enemies can find their way to that spot! That'd be cool!
PixElf: You've accidentally highlighted a small problem with my system, lol. At the moment, it doesn't use a direction-based line of sight. Basically, if you're behind the enemy, somehow he still sees you, LOL. Doh :|