Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Glenjamin on Sat 28/02/2015 17:13:58

Title: Following characters.
Post by: Glenjamin on Sat 28/02/2015 17:13:58
I'm trying to make it so the player is being persued by a monster between rooms.
I already have this command in place:
Code (ags) Select

cmonster.FollowCharacter(cEgo, 0, 20);


This works, but it cant follow the player between rooms. How can I do this?
Title: Re: Following characters.
Post by: Cassiebsg on Sat 28/02/2015 18:18:21
In which script is the command?
Needs to be in Global Scripts.
I have mine coded with "follow_exactly" so not sure if there's any trick when you're giving some space between them.
Title: Re: Following characters.
Post by: Glenjamin on Sat 28/02/2015 19:50:07
Please allow me to re-iterate on the concept.
I'm trying to make it so when the player picks up an object, it spawns the monster that will follow the player between rooms.
Title: Re: Following characters.
Post by: Cassiebsg on Sat 28/02/2015 20:58:24
I can't explain that much more other than that. When you add that command the monster should follow your character, also across rooms.

My code is for a backpack, reason I'm using follow_exactly, and works for me:

In Global Script:
Code (ags) Select

function oBackpack_Interact()
{
  // Grabs backpack and adds it to inventory
  cJake.Walk(mouse.x, mouse.y,  eBlock, eWalkableAreas);
  Player_Add_Inv(iBackpack);
  oBackpack.ChangeView(26); // Sets the Backpack character as blank/invisible view
  oBackpack.Solid=false;
  oBackpack.Clickable=false;
  oBackpack.FollowCharacter(cJake, FOLLOW_EXACTLY);
}
Title: Re: Following characters.
Post by: Glenjamin on Sat 28/02/2015 21:51:04
It's not working. My item is in a specific room, so how do I put the function in the global script?
Title: Re: Following characters.
Post by: HAL on Sun 01/03/2015 02:34:27
I think you're gonna have to programme it individually for each room.

And set a global bool variable for when the event is going.

Global Variable: MonsterFollowing = false;



function pickup_object()
{
   player.addinventory(iItem);
   monster.visible = true;       /// or however you plan for the monster to appear
   monster.followcharacter(cEgo);
   MonsterFollowing = true;
}

function leaves_right()
{
   player.changeroom(2, x, y);
   if (MonsterFollow == true)monster.changeroom(2, x, y);
}



/// in Room 2

function enters_room()
{
   if (MonsterFollow == true)monster.followcharacter(cEgo);
}     



Then remember to reset MonsterFollow = false when the whole thing is over.

There may be a more elegant way, but that's how I'd do it with my current AGS knowledge.
Title: Re: Following characters.
Post by: Slasher on Sun 01/03/2015 05:31:18
Code (ags) Select
cmonster.FollowCharacter(cEgo, 0, 20);
adding this after any event in any room will make cmonster character follow cEgo to other rooms.
You may need to tweak distance and eagerness to get it looking right.
Also FOLLOW_EXACTLY will put cmonster's x y the same as cEgo's x y (on top of!).
Both chars need to be on walkable areas i believe.

Check out FollowCharacter in the ags help file.

To stop cmonster following simply add:
Code (ags) Select
cmonster.FollowCharacter(null);


You can of cause also do a check to find out if cmonster is following.