Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Kamileon on Fri 13/06/2014 05:05:13

Title: Animating non-playable characters
Post by: Kamileon on Fri 13/06/2014 05:05:13
When the player enters room 2, I want a bird to fly in and land before the player has the option to move. The bird then talks to the player, before flying off again.

Is there a way to code the movement of the bird or would it be simpler to do with a cutscene?
Title: Re: Animating non-playable characters
Post by: Vincent on Fri 13/06/2014 06:45:17
This could be one of the worst ways to do it.
but maybe it could inspire you


bool first_time = true;
function room_AfterFadeIn()//room 2
{
  if (player.PreviousRoom == 1 && first_time)
  {
     StartCutscene(eSkipESCOnly);
     Mouse.Mode = eModeWait; //you can change this graphic, probably with no image at all
     if (!cBird.Moving) {
     if (cBird.x < 100) {
      // if the bird is on the left hand side of the screen,
      // start it moving towards the right
      cBird.Walk(400, cBird.y, eBlock, eAnywhere);
      cBird.Say("Hello There");
      EndCutscene();
      cBird.Walk(0, cBird.y, eNoBlock, eAnywhere);
      mouse.Mode = eModeWalkto;
      first_time = false;
   }
  }
}
}

Title: Re: Animating non-playable characters
Post by: Kamileon on Sun 15/06/2014 03:51:10
The movement of the character is working really well; thanks for the help Vincent. :smiley:
There is just one thing I need to add to the script, but am unaware of how to write it - how do I make the character leave the room? I tried using edges but didn't seem to work.

Code (ags) Select
function room_LeaveBottom()
{
  cBird.ChangeRoom(3, 155, 155);
}
Title: Re: Animating non-playable characters
Post by: Ghost on Sun 15/06/2014 04:06:08
Edges are only checked when the player character moves over them- your command would be triggered when the PLAYER leaves via the bottom edge.

A simple way is to use the Walk command with the eAnywhere parameter. Make a new walk command and set the y destination to higher than the room's height (in a 320x240 game, set y 0 260). This allows you to have the bird move OFFSCREEN (that's safe and a rather common technique).

After moving, you can call cBird.ChangeRoom(wherever).
Title: Re: Animating non-playable characters
Post by: Kamileon on Sun 15/06/2014 11:45:18
Thanks, working perfectly now :)