Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Enemy AI

Author
Message
Dante Labon
21
Years of Service
User Offline
Joined: 13th Oct 2002
Location:
Posted: 14th Oct 2002 07:40
Anybody got a decent code for enemy A.I? Something to make an enemy go from point a to point b (or patrol a set area) and if YOU (first person character) get close enough, It will chase.
Any help would be great.

Thanks.
Mirthin
21
Years of Service
User Offline
Joined: 13th Oct 2002
Location: Land of the Rising Haggis
Posted: 15th Oct 2002 00:25
Well, in theory AI is not so scary. Try going through pseudo code to get yourself a better understanding of what you want. There are two primary "detect factors." These are sight and sound. If you've had the opportunity to play Metal Gear Solid, or better yet, MGS2 you may find yourself analyzing such strategies.

Sight ) Create a cone that is positioned with the tip towards the enemie's eye, so that it spreads out. Make it invisible and get it to follow the enemy model, or you could make it part of the model I suppose. All that's left now is some simple collision work to set off your "I see you!" procedure. You will have to allow for crates, doors and walls to discount the cone, due to the fact that an enemy cannot see through walls, unless you want to give them x-ray head units.

Sound ) I'll discount gun noises. I think that's obvious. In the MGS series, there are three types of ground. Those that apply are loud and soft. You can approach an enemy on soft ground, but loud ground, that rattles or cracks or clicks beneath your feet will alert the guards. The final type of ground I will save for another category. You can make an invisible box appear whilst your character is in contact with the loud ground, but delete it when your character is stationary. When an enemy collides with this box, they are alerted, but you may want to have a "suspicion" routine, after all, it could just be another sentry doing their rounds.

There are secondary factors aswell, and since I'm in a good mood, I'll bother.

Smell ) This does not really apply to humans, but if you've got a creature with good olfactory perception, like a dog, then this may be a little more complex. You should have a sphere of odour around your character. The radius is up to you. If you are indoors, that will do. However, if you are outside then you'll want a wind. Wind should take, a cylinder perhaps from your character and dragged to the wind's destination. Keep the sphere, but push that back too. If you're downwind, you can sneak up on your monster, but the monster may smell you before you even hear it! That would add a great angle of atmosphere and skill to a game. Want to take it further? How about variable strengths. You gain smell slowly, it's a part of life. But if you run a lot, it will speed up the process. As your smell increases, your sphere widens and your cylinder lengthens. Four solutions.

1) The "Dip" : Find a body of water, and dive in! This will drop your smell level slowly.

2) The Lynx Effect : Find a can of deodourant (I'm serious) and give yourself a good spray. Get a deodourant, mind. Not aftershave that will attract the beast.

3) The "Radar Jammer" : Use some sort of citrus liquid like anti-mate to confuse your monster. It's pretty simple from here.

4) The "Good ol' Chum" : Use meat, or musk perhaps to direct the monster's attention to a particular place, like the radar jammer, but more directed. Note that you can place a sphere and cylinder there, but if the monster finds out, you can make it go berzerk when it finds that it's been played for a fool, if it's that intelligent. You could even splash some musk about your body, if you're suicidal.

The final factor is...

"Traces" ) If you do not cover your tracks, you could be in some serious trouble. Our final floor type is the depressable. Any surface that will leave a mark including snow, mud, wet sand and anything else that springs to mind. These will leave footprints, and guards will get suspicious. they'll probably follow the tracks which will end at your feet. Remember to allow for waves, or snowfalls/blizzards to eventually bury your tracks automatically. There are more sophisticated tracks, such as dead bodies, blood, bullet holes, blasted craters, etc. Use your imagination!

Phew! That was fun. as for implementing it, go ask your mother. I'm tired.

Hope this helped, It felt good to share my ideas. You can take these and add your own ideas and comments, but if you want info on the pseudo code e-mail me and I'll make up some examples.
Dante Labon
21
Years of Service
User Offline
Joined: 13th Oct 2002
Location:
Posted: 15th Oct 2002 14:35
Now that was a mouthful Thanks for the ideas. I'm still trying to put something together, and some of those ideas may help. I'll post it if I get it right.

Mirthin
21
Years of Service
User Offline
Joined: 13th Oct 2002
Location: Land of the Rising Haggis
Posted: 15th Oct 2002 14:49
Cool, thanks. It was great to lend a hand. I'll eventually run into this sort of practise in my idle coding, perhaps we can share source code and learn from each other.

Login to post a reply

Server time is: 2024-03-29 05:35:38
Your offset time is: 2024-03-29 05:35:38