Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Swordwielder on Sun 15/03/2009 23:32:56

Title: Making a NPC move.
Post by: Swordwielder on Sun 15/03/2009 23:32:56
How would I make my Non Player Character walk back and forth between 2 points? And if my player character collides with him, how would I make the game end?
Title: Re: Making a NPC move.
Post by: RickJ on Mon 16/03/2009 00:15:26
You would have to do something like the following.  The comments are self-explanatory.  Consult the manual for more detail, give it a try, and let us know how it works out.  ;)

int NpcX[2];
int NpcY[2];
int NpcPos;

function RepExec() {
     // Wait for Npc to stop moving
     if (!cNpc.Moving) {
          // Set the index for the next position
          if (NpcPos==0) NpcPos = 1;
          else NpcPos = 0;

          // Move NPC to the next position
          cNpc.Move(NpcX[NpcPos], NpcY[NpcPos], eNoBlock);
     }
     // NPC is moving so check for collision
     else {
          if (cNpc.IsCollidingWithChar(player) {
              // Characters are colliding so do something
          }
     }
}