🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

NPC AI

Started by
46 comments, last by Nazrix 22 years, 6 months ago
Some may know this already, but Wavinator and I have been working on a plot sytem for some time. The basic idea is that NPCs all have goals, desires, personalities, morals (good/bad), etc. They use this info in order to make decisions about what they want to do in the world. A bad NPC that is greedy may desire to break into the bank and steal a bunch of money (dumb example but it gets the point across). There could be a huge amount of interesting things the NPCs could do in a situation. For instance, one thing we thought of is NPCs could purposefully leave false information expecting to throw off other NPCs or the player such as leaving a note saying "We'll meet at the tavern" when they're really going somewhere else. I've already started getting some code together and basically any complex action such as this would be made up of smaller actions like (pick up, move, etc). This part is easy I think. The issue that I run into is: Should we have a big long pre-made list of somewhat specific things npcs can do in a situation and use some kind of exation that would let the NPCs determine what to do (including things like priority lists an such). This, I think, would be easy code-wise, but may feel a bit too scripted for my liking. The power of our concept here is, I think, the feeling that things are very loose and non-linear. Or is there a way to let NPCs find out ways to come up with solutions more on their own given some basic actions (walk, talk, etc) and basic knowledge of the world. I was thinking of letting the NPCs use trial-and-error many times before the game "starts" to learn about the world. They could learn what actions bring them to their desires and goals. I know that's not a new concept, but I am wondering just how far this could take it. I know Black & White did some stuff like this. Has anyone taken learning AI this far? Perhaps there is a nice medium where you're not making the NPC figure out everything by itself. You give it some higher-level tactics such as my "throwing the player off by giving false information" but let it learn strategies on its own too. Just some thoughts.... A CRPG in development... Need help? Well, go FAQ yourself. Edited by - Nazrix on October 6, 2001 4:00:57 PM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
Advertisement
I think you are planning far over your head. What you are describing is an articial intelligence i think nobody has been able to create yet. A while ago, i started writing my own AI code, using a simple realtime 2d game as test-subject. I planned to create AI similar to that seen in Metal Gear Solid, including line-of-sight, degrees of suspicion etcetc. Happy, eager and with lots of high hopes i started programming it, thinking it would take a day or two.

Some months later i had finally managed to let the enemies spot me when i came into line-of-sight. They chose from a list of standard actions based on my approach, like "alert others", "attack", "run away scared", "try to hide" and so on. All based on the enemies'' statistics (bravery, strength, tiredness, intuition, how many allies they can see etc)

This was a huge project for me, and i discarded all my plans to let the enemies become any more intelligent. Seeing how tough this was to implement in a simple action game, i''m getting fits just imagining how it would be in a rpg But i''m sure it can be done with enough effort.

My tip is, start out with the basics. Scrap what you have planned so far, and spend some time just learning your npc to move Its not as basic as you might think.

So what game are you creating? Is the engine finished? Always nice to see what fellow rpg-developers have done
- defster
Ugh, too many smileys...
- defster
Thanks for the reply, defster. I realize what I want to do is intense, but I''m just crazy and stubborn that way

I am using Nebula Device (free 3D engine). You can see some info from the link in my sig. if you''re interested.

I am doing this AI stuff in a text environment for testing however. I think the only severely difficult thing for me will be finding a fast way to store and retrieve info for the NPCs but I could be wrong.

A CRPG in development...

Need help? Well, go FAQ yourself.
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
Don''t tell me you''re wimping out already, Naz

Defster : What was your problem? What you proposed doesn''t sound too hard (or was this your first attempt at AI?)

Naz, if you''re prepared to spend a bit of time on setting it up, perhaps you could use a simple Roguelike as your test bed? It would give you an opportunity to test pathfinding, LOS (easy ), cooperative tactics, magic & weapons.

Roguelikes may look simple, but they''re extremely complex. Which is why I always take a look at the new graphical Roguelikes when they come out (like Pern). If they can make a Roguelike engine with Diablo graphics, and make it RT, I''ll be in heaven

And to save time answering your other thread, Braniac isn''t too bad, but I''m an advocate of learning & writing things from scratch. You invariably end up with something better, since you''re programming specifically to your needs, not trying to bend someone elses code to do what you want.

That''s enough for me


"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
quote: Original post by Merrick
Don't tell me you're wimping out already, Naz

No, of course not

quote:
Naz, if you're prepared to spend a bit of time on setting it up, perhaps you could use a simple Roguelike as your test bed? It would give you an opportunity to test pathfinding, LOS (easy ), cooperative tactics, magic & weapons.


maybe...but I think I'll just use my current testbed...LOS==much easier in 2D though right?

quote:
And to save time answering your other thread, Braniac isn't too bad, but I'm an advocate of learning & writing things from scratch. You invariably end up with something better, since you're programming specifically to your needs, not trying to bend someone elses code to do what you want.


Braniac seemed like it is along the same lines as I am thinking but I agree with you. I'd rather build it from scratch so it fits my needs exactly.

I know that's the same thing people say about using someone else's 3D engine, but I still feel that Nebula 3D is general enough and powerful enough to fit my needs.



Edited by - Nazrix on October 8, 2001 6:45:23 PM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
quote: Original post by Nazrix
maybe...but I think I'll just use my current testbed...LOS==much easier in 2D though right?

Yes, but not that much. The same theory applies in 3D. Cast a ray from your position to the enemy, and check to see if an obstacle is in the way. The only difference is that in 3D, you check the height of the obstable as well to see if it's high enough to block your view. It's only a little bit of trig. Not too intensive if you've got lookup tables.

Now, to just go off-topic SLIGHTLY, I don't know if I've mentioned it to you before, (I know I have to Dwarfsoft), but in my RPG I've got a banking system going (your example of robbing a bank reminded me).

I've implemented a system of Repositories (banks) which show up in towns and cities. These are run by a neutral race of telepaths, who can communicate over vast distances (thus keeping balances up to date and accurate). At these Repositories, you can deposit & withdraw money, (and earn interest on banked money), which is essential for safeguarding your money, since if you leave it lying around, it'll get stolen.

It also allows the player to build up enough cash to buy their own house. I think that if you can buy a house, you should start off with one, even if it's your Lord's or your Parents'. In my case, the player belongs to a Faction, which houses its members in a large Tower, and at the start of the game, you are chosen for a mission, and so leave the Tower. You can return there from time to time (for healing, and to save the game (since your Home is one place you can always save in - sacred places are the other)), but since it is usually a long way back, it makes sense to get a better place.

Anyway, not only does your house provide a safe place to sleep & store extra items, (and a place to save), but you can also set up up to 8 Portals around the world. Once these are in place, they can't be changed, and they require time to create. But once they are created, you can travel from the portal to your house, and back (or to any other portal) in a matter of seconds. The last benefit of having your own house, is that the locals treat You as a local, and share much more information than they normally would.

Houses can be bought or built - either buy a house for sale in a town you like, or buy land, and choose a house design. Then the local builders begin, and you come back when it's finished (since it takes a while to build a house). This is a trade-off between immediate access to a house, and a bigger & better house to what would normally be available. You could even choose a Palace if you're the greedy type.

And, not only should the player be able to buy a house, they should also have a remote chance of being gifted one.

The point of saying this (not just to show off ), was as an example of NPCs showing intelligence. If your NPCs can bank their money, not only will they not have large amounts on them when you kill them, but the longer they stay alive, the more money they will obtain, and so the better equipment they can afford. So you have another aspect of planning, where your NPCs can upgrade their items properly, and so the game becomes more like a Strategy game than an RPG, because the longer you muck around trying to max out your character, the stronger your opponents are becoming, so you never actually have to make hard enemies, they develop that way.

Hope that made sense


"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick

Edited by - Merrick on October 8, 2001 7:22:55 PM
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
Perhaps I should reply to the actual post?

quote: Original post by Nazrix
Or is there a way to let NPCs find out ways to come up with solutions more on their own given some basic actions (walk, talk, etc) and basic knowledge of the world.

Let''s briefly look at two options (there are more, but I don''t want to spoil the surprise)

1. You can set up items with attributes such as Open, Unlock, Light, Cut, etc., and features with attributes such as Openable, Lockable, Lightable, Cuttable, etc.

So a Door might be all four of the above. So your NPC tries to open it, but it''s locked. So he looks in his inventory for something that can unlock a door (key, lockpick etc.). Nope, nothing there. So he might try to set the door on fire, or he might have an axe, and cut through the door.

2. You have items that have properties which affect certain elements. An AXE may affect WOOD with a method of CHOP, and a DOOR may be made of WOOD, with the result of SPLINTER when CHOPped.

So the NPC comes along, uses the AXE on the DOOR, the DOOR recognises that the AXE affects it, and splinters in two, allowing the NPC to go through.

The second is almost like a messaging system. Instead of checking for everything in a loop, you simple call Door->Effect(AXE); or something similar
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
quote: Original post by Merrick The point of saying this (not just to show off ), was as an example of NPCs showing intelligence. If your NPCs can bank their money, not only will they not have large amounts on them when you kill them, but the longer they stay alive, the more money they will obtain, and so the better equipment they can afford. So you have another aspect of planning, where your NPCs can upgrade their items properly, and so the game becomes more like a Strategy game than an RPG, because the longer you muck around trying to max out your character, the stronger your opponents are becoming, so you never actually have to make hard enemies, they develop that way.

Hope that made sense


Yes, I thought of NPCs owning houses for sure. I hadn''t thought of the consequences such that NPCs would get stronger as they go and that would make it closer to a strategy game. What I am going for is strategy/rpg/sim, so that would certainly fit. Thanks for the info



A CRPG in development...

Need help? Well, go FAQ yourself.
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
quote: Original post by Merrick
1. You can set up items with attributes such as Open, Unlock, Light, Cut, etc., and features with attributes such as Openable, Lockable, Lightable, Cuttable, etc.

So a Door might be all four of the above. So your NPC tries to open it, but it's locked. So he looks in his inventory for something that can unlock a door (key, lockpick etc.). Nope, nothing there. So he might try to set the door on fire, or he might have an axe, and cut through the door.

2. You have items that have properties which affect certain elements. An AXE may affect WOOD with a method of CHOP, and a DOOR may be made of WOOD, with the result of SPLINTER when CHOPped.

So the NPC comes along, uses the AXE on the DOOR, the DOOR recognises that the AXE affects it, and splinters in two, allowing the NPC to go through.

The second is almost like a messaging system. Instead of checking for everything in a loop, you simple call Door->Effect(AXE); or something similar


I was thinking in terms of #2 a bit more. I already have a sort of message system in place now except it doesn't include items and objects yet...just NPCs are able to message other NPCs so far. As in, NPC 1 tells NPC 2 that he kidnapped him or whatever. It works pretty well.


A CRPG in development...

Need help? Well, go FAQ yourself.


Edited by - Nazrix on October 8, 2001 7:52:40 PM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi

This topic is closed to new replies.

Advertisement