Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Icey on Tue 21/09/2010 22:16:19

Title: how to make villigers(AI) walk from room to room?
Post by: Icey on Tue 21/09/2010 22:16:19
In my upcoming game there is a part that has be bugging me for the longest time.I want to know if I can make the people in the town walk around freely from room to room or just with in that same room.I don't want to code the wrong thing then save the game and end up messing it up.
Title: Re: how to make villigers(AI) walk from room to room?
Post by: Matti on Tue 21/09/2010 22:22:49
You should take a look at the Character Control Module (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=28821.0).
Title: Re: how to make villigers(AI) walk from room to room?
Post by: Icey on Tue 21/09/2010 22:47:08
funny thing is that is in my game I have know idea how to use it.only reason i left it in the game is because it never messed with the game. does any one know how to use? maybe just some code to make ego(AI) moving around while christen is moving.
Title: Re: how to make villigers(AI) walk from room to room?
Post by: Wyz on Wed 22/09/2010 00:07:12
Do you want to have them wonder around aimlessly or let them focus on certain spots?
In the latter case you can just use something like this:


function room_RepExec()
{
  int ran = Random(500);

  if (!cCharacter.Moving)
  {
    if (ran == 0)
      cCharacter.Walk(100, 150, eNoBlock, eAnywhere);
    else if (ran == 1)
      cCharacter.Walk(200, 300, eNoBlock, eAnywhere);
    else if (ran == 2)
      cCharacter.Walk(50, 100, eNoBlock, eAnywhere);
  }
}
Title: Re: how to make villigers(AI) walk from room to room?
Post by: Icey on Wed 22/09/2010 20:23:00
Can I use that code to set views for objects that are people and make them move with the code ?
Title: Re: how to make villigers(AI) walk from room to room?
Post by: Khris on Wed 22/09/2010 23:56:19
No. No you can't.

Why objects? You can move objects, but they won't walk. Even if you animated them using a walk-cycle, you'd have to manually change the loop according to the direction they move in.

I would do this:
In each room's before fadein, store exit and points of interest coords in arrays. As a third parameter one could use the direction, i.e. is it a north exit / is the market stand to the left of its POI coordinates.

In repeatedly_execute, if the current room is marked as one with villagers walking around, use the first free character of a set of villager characters and randomly choose a route, e.g. enter through exit 2, go to POI 1, wait 4 seconds, exit through exit 4. To make them walk the route, either use the CharacterControl module or code it manually; that would involve creating an event queue mechanism.
When they leave, mark them as free.
Repeat.

The illusion is broken only if the player decides to follow a specific character and won't find them in the next room. Of course one could also code it that way; people actually moving from room to room; not sure if it's worth the trouble though.