Wintermute Engine Forum
Wintermute Engine => Technical forum => Topic started by: Old_Guy on September 29, 2007, 08:34:48 PM
-
I'm a complete noob with a (probably) dumb question.
I am making a 2D game. It is my first shot with WME :)
Is there a way to make selected NPC's "follow" my main actor where ever he goes (as if the NPC is being led by the hand so to speak)?
-
you can have a daemon script which would periodically check the X and Y position of your lead actor and then call GoTo method of support
actor. Try it and if you're still unsure, I'll post some code.
-
Very cool. Thanks! I'll give it a shot.
-
The Old Guy hasn't quite been able to pull it off. ???
And so I come a beggin' for the aforementioned code . . .please.
-
If you're referring to the same OldGuy from the demo, then if memory serves, he is an Entity and not an Actor. Entities can't walk in WME, if I recall correctly, and therefore they don't have any GoTo() method. If that is really the case, you should try what meta recommended but this time with an Actor instead of an Entity and it should work.
Oh, and welcome to the forum, by the way :)
-
I rather think he's referencing himself ...
-
I rather think he's referencing himself ...
Could be... I'm just not very used to people using third person to refer to themselves...
-
Yes, he was referring to himself. Sorry for the mix up.
-
First of all we're going to tweak the main actor script file (it's usually called actor.script and is located in the actor's folder). We'll add here custom
method GoTo, which will override the original.
method GoTo(posx,posy)
{
// We store some attributes to indicate, that our actor got a Go To command
this.newWalking = true;
this.targetX = posx;
this.targetY = posy;
// we call the original Go To
this.GoTo(posx, posy);
}
Now we modify the script for the second actor:
#include "scripts\base.inc"
while (1)
{
if (actor.newWalking)
{
actor.newWalking = false;
if (this.IsWalking()) this.Reset(); //if our support cast already moves, stop him
this.GoTo(actor.targetX, actor.targetY); // send support cast to the leading role character.
}
Sleep(100);
}
Sorry, I can't test it right now, but should work.
-
I would add a trigger to the endless loop, something like
while (1) {
if (isFollowing){
your stuff here
}
}
So you can trigger wether actor 2 should follow or not.
-
yes but for understanding the principle it's better to present the minimal version and build on it. ;)
-
Thank you very much, kind Sir : ).
-
Here is my final non-elegant tweaking. It seems to work great. It lets me take hold of the npc and lead it until I "re-take", which then lets go of the npc.
In the NPC's .script file:
=================
on "Take"
{
if (this.isHeld)
{
this.isHeld = false; // Let go of the NPC
}
else
{
GoToObject();
this.isHeld = true; // Hold the NPC
FollowHim();
}
}
function FollowHim()
{
while (this.isHeld)
{
if (actor.newWalking)
{
actor.newWalking = false;
if (this.IsWalking()) this.Reset(); //if npc is already moving, stop him
this.GoTo(actor.targetX-25, actor.targetY-25); // send npc to the main actor
}//end if
Sleep(100);
}//end while
} // end FollowHim
Many thanks :)
-
the only suggestion would be to define your "following" function as a method instead of function.
This way you could also trigger the follow mode outside of the script through:
npc.FollowHim();
-
Excellent idea. TYVM ! : )