Members - Reputation: 631
Posted 03 February 2000 - 11:14 AM
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
case 1: // go up & right
There''s nothing intelligent about it.
Posted 03 February 2000 - 03:35 PM
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.
Members - Reputation: 122
Posted 03 February 2000 - 10:21 PM
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.
GDNet+ - Reputation: 276
Posted 06 February 2000 - 11:31 AM
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.
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
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.
From the High Mountains of Colorado