Following characters.

Started by Glenjamin, Sat 28/02/2015 17:13:58

Previous topic - Next topic

Glenjamin

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

cmonster.FollowCharacter(cEgo, 0, 20);


This works, but it cant follow the player between rooms. How can I do this?

Cassiebsg

#1
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.
There are those who believe that life here began out there...

Glenjamin

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.

Cassiebsg

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

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);
}
There are those who believe that life here began out there...

Glenjamin

It's not working. My item is in a specific room, so how do I put the function in the global script?

HAL

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;

Code: ags


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);
}


Code: ags

 /// 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.

Slasher

#6
Code: ags
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
cmonster.FollowCharacter(null);


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


SMF spam blocked by CleanTalk