(SOLVED) Animating non player characters

Started by Derrick Freeland, Tue 30/11/2010 15:23:03

Previous topic - Next topic

Derrick Freeland

So,
I'd like to set up a non player character in my first room, and have them walk around the room (in this case, it's just back and forth).  I've got the animation frames plugged into a loop on a specific view, and I've got my non player character attached to that view, but when I load up the room in game, the character just stands there. 

My question is this:
How do I get a non player character to automatically walk around a room, or run through an animation cycle?

Khris

If you make an NPC walk, they'll use the frames in their NormalView to animate the walking.
If your NPC is called cGuy, this will make them walk in the background:
Code: ags
  cGuy.Walk(x, y);

The other parameters of the command are optional, and the defaults are non-blocking movement within walkable areas.

To make them walk back and forth, add the repeatedly_execute event to the Room and in there, if the character isn't moving, send them on their way:

Code: ags
function Room_RepExec() {

  // NPC walking back and forth
  if (!cGuy.Moving) {
    if (cGuy.x < 160) cGuy.Walk(300, 160);
    else cGuy.Walk(20, 160);
  }

  ...
}

Derrick Freeland

Thanks for the advice and code.  I'm still having trouble making it work, but that's because I'm an AGS newb it's not clear yet how to put the code into my game.  Checking out the tutorial now, hopefully that will point me in the right direction  :-\

Khris

Open the room and make sure the dropdown menu beneath the project tree says "(Room; number X)".
Now click the lightning bolt icon to bring up the room events pane.
Click on "Repeatedly execute", then the ...-button in the field next to it.
This should open the room script and add this to its end:
Code: ags
function room_RepExec()
{

}


Now put the code in there.

Derrick Freeland

Sweet zombie Jesus, IT WORKS!!! ;D 

The game... it's... IT'S ALIVE I TELL YOU, ALIVE! 

Ok, so that's a bit melodramatic, but it is very nice to see the game world come alive and function on its own.  Thanks so much for the help.

SMF spam blocked by CleanTalk