Basically, if you want the player to retain control over the ego-character you should not use any blocking commands.
There is a special FollowCharacter(Ex) function you can use to make NPC follow the player:
enter room after fade-in:
int dist = 1;
int eagerness = 20;
FollowCharacterEx (NPC, GetPlayerCharacter(), dist, eagerness);
repeatedly execute:
if (AreCharactersColliding(NPC,Ã, GetPlayerCharacter())
{
Display("Here comes a death animation.");
}
if you want something to happen when character NPC is close to you.
use this script in the rep_ex:
if (character[EGO].x < character[NPC].x + 50) {
if (character[EGO].x > character[NPC].x - 50) {
Display("Here comes a death animation.");
}
}
That's if you want EGO to dye when NPC is 50 pixels near EGO
(before the characters colide).
Thanks for help. Both of you!
But that +50 and -50 is still a bit mystery to me. I know that it means that distance, right? But what are the exact meanings with - and +?
Thanks again!
mouse.x + 50 and mouse.x - 50 do exactly what they say. They add/subtract (respectively) 50 from the x position of the mouse (mouse.x).
Quote from: Rd27But that +50 and -50 is still a bit mystery to me. I know that it means that distance, right?
Yeah, they specify how close the NPC must walk up to the player character for the animation to start playing.
As Ashen suggested, you can as well add an y-coordinate check. Here is an example:
+---------> x
|
|
|
V y
Ã, Ã, Ã, \----50----|----50----/
Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |
Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, Ã, Ã, (NPC)
Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, 20
Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |
Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |
Ã, Ã, Ã, |--------(Plr)---------
Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |
Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |
Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, 20
Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |
Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |Ã, Ã, Ã, Ã, Ã, |
Ã, Ã, Ã, /----------|----------\
(Plr) - player character (EGO)
(NPC) - NPC is outside the bounding box
if ( (character[EGO].x < character[NPC].x + 50) &&
Ã, Ã, Ã, (character[EGO].x > character[NPC].x - 50) &&
Ã, Ã, Ã, (character[EGO].y < character[NPC].y + 20) &&
Ã, Ã, Ã, (character[EGO].y > character[NPC].y - 20)
Ã, Ã, )
{
// NPC is inside the bounding box:
<animation code here>;
}
EDIT: Here is the exactly same piece of code but written in a slightly different manner to be consistent with the picture above:
if ( (character[NPC].x > character[EGO].x - 50) &&
Ã, Ã, Ã, (character[NPC].x < character[EGO].x + 50) &&
Ã, Ã, Ã, (character[NPC].y > character[EGO].y - 20) &&
Ã, Ã, Ã, (character[NPC].y < character[EGO].y + 20)
Ã, Ã, )
{
// NPC is inside the bounding box:
<animation code here>;
}