coding question...

medic

Newbie
Joined
Jul 19, 2003
Messages
89
Reaction score
0
When Valve makes the AI to Half-Life 2 how do they do it?

I really cant understand how they can make this "person" and teach the "npc" to use the gravity around him, uses guns, etc etc...
How does the code for the AI looks like... Can someone just answer in a short way... Im not a coder Im a leveldesigner so im not so bright when it comes to this things!

thx
 
In order to tell you that, I'd need about 6 months to teach you how to professionally code in C++ So I'll keep it short - they're special people. :)
 
If you want to break it down to the simplist level, it is a series of if->then statments.

If and enemy shoots at me
Then I do 1 of many things

If I see an enemy
Then I shoot




Basicly, thats what it is, plus about 5 million options and variables.... fun stuff :)
 
SideWinder: Well that isent so hard... lol... It is built by if states? I thougt that... humm... Its really amazing what they can do!
This hole thing to lurn the npc walk throw doors, and stuff understand the enviroment.
 
If, or, else ...MUAHAHAA!!! ...lets say you want a character to uhm .. live in his house and do things when you enter it... yeeah... you just go
if player in the house
do blablabla

else go to sleep

or

go to bath...


ok getting carried away here..someone stop meee....ok... ;)
 
Its really wacked that coders can do all that things they do!
 
"where might i find the .cpps for that?"

They may release them with the sdk. Otherwise how are we going to code decent single player mods? :)
 
yeah i really hope they support the single player mods as much as they will the multiplayer ones.
 
AI is some of the most complicated code to write. There really is a lot more than just conditional statements. However, basically it is a series of checks for various conditions within the environment and the player(s). Then writing extensive functions that control the actions and define "perceptions" of individual AI characters. Conditionals are some of the most common used statements in all programming languages. Doing a quick search should return several results.

Being an experienced coder, I wish more people would attempt to learn how to program. Most people don't like the daunting look of 50,000 lines of code, but it too is an artform in it's own right. Just as 3d modelling or level design. My favorite part of being a programmer is having full control over the game itself. You get to decide how items and players react in a set environment. Artwork is just a pretty picture until you can get it ingame and working correctly. :cool:
 
Originally posted by Sirius
Being an experienced coder, I wish more people would attempt to learn how to program. Most people don't like the daunting look of 50,000 lines of code, but it too is an artform in it's own right. Just as 3d modelling or level design. My favorite part of being a programmer is having full control over the game itself. You get to decide how items and players react in a set environment. Artwork is just a pretty picture until you can get it ingame and working correctly. :cool:

amen
 
HeY, I`m a coder, unfortunatelly not too experienced (yet) but what makes me wonder about this AI in HL2 is : do they use neural networks? If not, then what they use? Could someone from the coders team answear this question?




N3T
 
Originally posted by n3t
HeY, I`m a coder, unfortunatelly not too experienced (yet) but what makes me wonder about this AI in HL2 is : do they use neural networks? If not, then what they use? Could someone from the coders team answear this question?




N3T


They might, but believable AI can be achieved with simple logic tree structures and basic agent programming. My guess is they have preprogrammed "brains" and depending on the need will use smarter brains for smarter NPC's and baddies. For example, zombies and ant lions could use simple logic routines, such as "my target is at B, I'm at A, I'll choose the shortest path between A and B, regardless of the swinging blade." However, "smarter" creatures will make decisions about the environment, etc. (still not n.net). Even when the ant lions interact, that could be very basic agent programming using simple logic routines.

AI can be very taxing on a system since intelligence in computers is generally defined by the volume of information used to make any given decision. I've worked with off-the-shelf n.net's before, such as those from NeuroSolutions. Making accounting and finance decisions eats up the CPU pretty fast.

So it's possible that the human NPC's are using a n.net process or CART/MARS, but my guess is that the ant lions and drone guns aren't.

-Mr. Bildo
 
very interesting question indeed, we can only wait to see, and dont forget that they are still using flags within the level to "help" the AI , like telling it heres a good place to hide/reload , heres a window (look/shoot thru) , its not really scripted, but its not just a bot thrown into a level and it thinks fully on its own

this is just what I believe (from reading lots of stuff) so I may def be wrong ;-)

and did you ever notice that the baddies in the HL cant shoot while moving, I never really noticed that till I read some response by Gabe in an email in this forum, im like "holy &^%$ they never did move while shooting and they still rocked us all"!
 
I think using flags to indicate particular environmental factors is the best any game can do at this stage. This however, is perhaps the most important of any factor in future AI programming. The AI must react to the environment (props, other npcs, etc.) to determine its behavior. For example: 'Oh, it's a window -- I can shoot through the glass.' Unfortunately, a game isn't and can't be like real life where the AI can be "nurtured"/conditioned to recognize stimili. When you play a game the first time, you want it to be as believable as possible. Instead of having the AI SEE a window and recognize it as a window, the window is simply flagged (works well, but the poor mapper...) to allow for a jump-in-and-play.

It would be wonderful when the AI can analyze the geometry of its environment and properly hide itself behind an angled wall. This would be a mapper's delight, I think (no flagging, so the AI can handle any situation). But, this is a long way UP the road into the later age of 64-bit computing.
 
Neural Nets can be defined as several functions running simultaniously communicating to each other info or to a central "brain", each perhaps helping to learn and adapt from past experiences...

While the average AI opponet exsists only for a short while till you kill him, it doesnt have alot of time to adapt or learn.

AI would in a fight, keep track of what actions he took and record the results. All that information would build up to a very complicated a CPU intensive judgement call on what action it should take next based on what happened in the past for such a similar situation..

I would imagine they fake AI to a degree to reduce the code stress by the above mentioned - flaging the map area, and similar tricks.

You could imagine though one of the things AI would want to know is where it is relative to any solid object at any given time... rather than run into it, it would "see" the wall.. To "see" the wall is where it gets complicated without flaging the environment in the map editor ect.

A global coordinate system[in 3D mind you] is one thing, and perhaps a invisible bounding shape for collision data is another...

That all is just for a basic eyeball on a stick with wheels...

AI needs to know what animations to play, what direction to face, the path around an object, how to jump over or on something, the correct weapon and be smart enough not to shoot himself in the foot, let alone track and kill a moving object appearing realistic without looking like hax ;]

I think thats the biggest challenge is making it look "normal" and not like the AI is "cheating", often times its apparent that the AI knows exactly where you are when you know it shouldnt. Sometimes you can just feel the AI looking at you behind a wall ;]

Then of course when your behind the wall, all the AI freezes like "awe come out and play" and you know they wont come get you because they are not programmed to. Sure if you hide, thier waypoint patrol is activated and if they see you on thier waypoint then...But still, they cant really think of where you might have gone..perhaps though like you remember where you last saw something, it does to.. If allowed to go to it, it will. Thats the best AI. That really is just a varible that is frozen as a coordinate when your out of site. Tracking, tracking, tracking, hes gone, what was the last coordinates.. lets go get him. At the same time while they come after you, be smart enough to take cover along the way..or maybe the spot they have now is the best. How does it really know what is best at any given time? Logic or common sense.. How do you teach common sense? I know plenty of humans that dont have it let alone AI.

Another example, say you trigger thier alert waypoint and so they start to patrol along the assigned waypoint, they wouldnt bend down and look under the table if thats not a part of thier waypoint actions..

Im not even a programmer, this is all observable behavior. Naturally the coding side of things is another perception and language of understanding how things work.

Interesting though someone mentioned the AI in HL2 cant move an shoot at the same time. I cant think of any reason why its not possible.
 
you should read more carefully, I stated in the original HL, they could not move and shoot at the same time
 
layek: i enjoyed reading your post. you seem to have a good understanding of the general approach to game AI. certainly more than i.

i recently finished a pretty good book on the histroy of artificial life that really opened my eyes. as far back as maybe the late 70's (maybe 80's) this guy developed a system with simple creatures that were allowed to evolve and adept in any way they needed in order to survive.

the crazy thing is - without being preprogrammed, things like parasites and even meta-parasites began evolving. creatures were also tricking others into raising their children.

the program was called tierra if you want to know more.
i find the prospects of game aLife really fascinating. the way truly staggering behavior could seemingly burst forth from (relatively) simple rules. i think flocking / swarming / group behavior is going to be really fun to see in hl2.
 
Yeah, the hoard behavior has potential to be really deep. It would be nice to see groups of enemies communicating and sharing information as they discover it.

HL2 looks to have the best AI overall, all though other games like Deus Ex: Invisible War, Thief III, STALKER, or Far Cry may possibly take the cake. Really hard to tell without seeing it in action like we have for HL2.

One thing that really amazes me with HL2 is how it's unscripted yet so intelligent. Autonavigation isn't new exactly, but HL2 seems to have taken it further.

I loved the scene in Trapdown where Gordon ran inside, shut the door and moved the table infront of it. The enemies shooting through the window wasn't that amazing, but when the guy plowed through the door, oh wow. The AI tried to open the door a few times, realized it was closed, so backed off, and rammed into the door (or kicked it, I don't remember). That's what really impressed me.
 
Originally posted by Emon
(or kicked it, I don't remember)

Yeah I think he kicked it, or maybe he changed his arm into a hydra tenticle and plowed the door with it, EVERYBODY GO CHECK OMGZOR!
 
Well, another thing to htink about is the differance between 1player AI and bot AI.

in single player, the AI are supposed to die. weather or not they're on hard or easy difficultly, they are there to present the player with a challange, but not beso good as to seem "cheap" (sniper town, MOHAA).

However, in bot AI, they need to attempt to simulate a human opponet, which is very, very difficult, due to the whole "lets be un predicable" thing us humans have.
 
speaking of books, if AI intrests you, you should check out Prey by Michael Crichton, very fictional, but has to deal with renegade nano bots and AI behavoirs
 
I would assume that HL2 has code similar to HL. Take a look at the SDK, especially(for single player src) the "dlls" directory.

The code is heavily commented, so you can see how the ai works. It all seems to be based on some sort of event scheduling.

Well, one _could_ rewrite everything, but I think the preferred action would be to simply modify parts to fit your mod...
 
It would be cool if you could program AI bots that learn.. so if something keeps happening which they die from then they learn and try to stop dying
 
Originally posted by smilez
It would be cool if you could program AI bots that learn.. so if something keeps happening which they die from then they learn and try to stop dying

Yes, it would. But I'm not certain that it is really possible right now. In multiplayer games, you could teach bots to imitate player paths for successful players, or assign certain characteristics to "watch", but we are too far away to actually teach bots the intuitive reasoning that says "I got my head blown off for not watching my back, so now I'm going to turn around every once in a while". It is much better to anticipate such things and build them into bot behaviour. I thought the HL1 bots did a pretty good job of it, except for the part where they relocate in the middle of a firefight...

K
 
How are we supposed to tell you how something we've never seen is coded? :|
 
Back
Top