how to make villigers(AI) walk from room to room?

Started by Icey, Tue 21/09/2010 22:16:19

Previous topic - Next topic

Icey

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.


Icey

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.

Wyz

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:

Code: ags

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);
  }
}
Life is like an adventure without the pixel hunts.

Icey

Can I use that code to set views for objects that are people and make them move with the code ?

Khris

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.

SMF spam blocked by CleanTalk