Make a character follow

I have a character-object, but I want them to follow me around.


On the game object is a script named roomenter which runs every time the pllayer moves to a new room. I think it's on the "scripts" tab, but I can't remember what the caption says. It should be pretty obvious.

You could have that script check if the NPC should be following right now, and if so move them into the player's room.

(Sorry I can't give more confident explanation, I'm still trying to put everything together again after a hard drive failure)


continuing with 'mrangel' post's content:

for the scripting, an example of the 'follower' coding:

(if you want multiple npc/party/team members, following a main character, let me know)

if (not npc.parent = player.parent) {
  npc.parent = player.parent
}

the 'parent' Object (pointer/preference: ADDRESS) Attribute is how location/placement/heirarchy actually is controlled

conceptually, this is how the scripting works:

OBJECT_1.OBJECT_1'S_LOCATION = DESIRED_LOCATION

DESIRED_LOCATION = OBJECT_2.OBJECT_2'S_LOCATION

OBJECT_2.OBJECT_2'S_LOCATION = CURRENT_LOCATION

OBJECT_1: npc
OBJECT_1'S_LOCATION: parent
DESIRED_LOCATION: player.parent

OBJECT_2: player
OBJECT_2'_LOCATION: player.parent
CURRENT_LOCATION: {WHATEVER: the Room that the 'player' has just moved to / is current at}

for example:

initial/starting locations:

player.parent = room_1
npc.parent = room_1

'player' moves to room_2:

player.parent = room_2

then, the 'follower' scripting/code (such as if within this Scripting/Script-Attribute of the 'game' Object as used in mrangel's post: game.roomenter), checks if 'npc' is in the same room as the 'player, which it isn't:

player.parent = room_2
is NOT equal to
npc.parent = room_1

so, the 'then' in the follower scripting/code, sets the 'npc.parent' to the same room/location/parent as the 'player.parent':

npc.parent = player.parent

// conceptually, what it does:

// player.parent = room_2
// npc.parent = player.parent
// npc.parent = {player.parent = room_2}
// npc.parent = {room_2}
// npc.parent = room_2

// the 'npc' has "followed" the 'player', both are now in 'room_2':

// player.parent = room_2
// npc.parent = room_2


Log in to post a reply.

Support

Forums