Civilian AI

Started by
4 comments, last by DarkMage139 24 years, 3 months ago
I''m making an RPG that has plenty of civilians in it. My question is HOW DO I MAKE A "WANDERING" AI. The civilians are supposed to wander around aimlessly, but I don''t know how to write an AI for that. - DarkMage139
- DarkMage139
Advertisement
Randomless AI == rand() %8

If you have eight directions, do a rand(), mod it by 8, and use a switch statement to see what to do in each case:

switch (rand() % 8)
{
case 0: // go up
locationY--;
break;
case 1: // go up & right
locationY--;
locationX++;
break;
.. etc.

}

There''s nothing intelligent about it.
The other thing to do is to design some patterns for the people to follow. You can have some do circles, or whatever. Once you get numerous civilians, each running one of a few set patterns, it will seems like they are wandering around aimlessly.

You can make an array of integers, each with a number 1 throgh 8 (for the 8 directions described above). Then, each civilian has a pattern integer and location integer (the location in the pattern''s array) in the structure/class. You then use the code in the previous post to move the people around. Of course, when the pattern comes to completion, you reset the pattern location integer to 0. At this point in time, the civilian may or may not be in the same position he started. It doesn''t really matter, just be sure you don''t put a lot of the same numbers in the pattern, in case the civilian gets next to a wall or something.

This will add a little more control to what the civilians do.

Ben
By ''wandering'' I assume you do not mean entirely random, just that you want them to look like they are going about their own business.

You could try a simple state-based system. Maybe a moving state and a choice state, or something like that.

Basically you could use the random idea from above each time the civilian is in the choice state, to select a direction to move in. From there the civilian switches into the moving state and might move in the random direction for ten spaces, or ten units of time or whatever.

Then they return to the choice state to make a new decision on direction.

Just an idea.

Woop
quote:Original post by DarkMage139

I''m making an RPG that has plenty of civilians in it. My question is HOW DO I MAKE A "WANDERING" AI. The civilians are supposed to wander around aimlessly, but I don''t know how to write an AI for that.

- DarkMage139


Hey DarkMage:


Well, I assume you''re after some behavior on the part of the NPCs that at least makes them look like they''re actually "living a life", right? The Ultima games do a pretty darn good job of that.

As one person already suggested, a simple state system can help you with this. Pick out a half-dozen occupations your NPCs will do in their village or town or whatnot, then set up a simple 3- or 4-state engine for each of them. For example, a ticket salesman at a railroad station might do the following:

State 1 (default) - Sits on bench at window waiting
to sell somebody a ticket.
State 2 - Puts up the "Went to Lunch" sign and walks
to the railroad cafeteria. Returns to ticket
counter.
State 3 - Sings a little diddy about a travelling
salesman and a minister''s daughter.
State 4 - Stands up in his office behind the counter
and shuffles some papers around; returns to State
1 when somebody comes up to buy a ticket.


A crude example, but with just a few of these you can quickly bring an area to life. Of course, if a player stands around forever and watches everybody he''ll sooner or later pick up the pattern--but if they just move through the railroad station en route to other areas of the game it''ll look pretty good.





Ferretman

From the High Mountains of Colorado

Ferretman
ferretman@gameai.com
From the High Mountains of Colorado
GameAI.Com

Thanks for all those ideas, everyone!

- DarkMage139
- DarkMage139

This topic is closed to new replies.

Advertisement