M
Mandarieno
Guest
Hello,
I have written a script for my npc's to make them always face the player by using the built in function "point_direction". I am happy with how this works but now I want them only to face the player when he is in a specific range to them.
I use "distance_to_object" for this and that also works fine except for one glitch that I don't seem to understand.
At the corners of the detection of "distance_to_object", the npc's always jump from their facing sprite to their default sprite (default sprite is used for when the player is not in range) and back in a loop.
I don't understand why this happens. This means at that x and y point, the game can not decide if the player is in range or not? Or rather both cases are true?
I hope you guys can help me understand why this happens and maybe help me solve the problem
I have written a script for my npc's to make them always face the player by using the built in function "point_direction". I am happy with how this works but now I want them only to face the player when he is in a specific range to them.
I use "distance_to_object" for this and that also works fine except for one glitch that I don't seem to understand.
At the corners of the detection of "distance_to_object", the npc's always jump from their facing sprite to their default sprite (default sprite is used for when the player is not in range) and back in a loop.
I don't understand why this happens. This means at that x and y point, the game can not decide if the player is in range or not? Or rather both cases are true?
I hope you guys can help me understand why this happens and maybe help me solve the problem
Code:
///NPC FACING SCRIPT
dir = point_direction( x, y, player.x, player.y );
if (distance_to_object(player) <= 16)
{
if(dir > 45 && dir <= 135)
{
sprite_index = spr_n;
}
else if(dir > 135 && dir <= 225)
{
sprite_index = spr_w; image_xscale = 1;
}
else if(dir > 225 && dir <= 315)
{
sprite_index = spr_s;
}
else if(dir > 315 || dir <= 45)
{
sprite_index = spr_w; image_xscale = -1;
}
}
else if (distance_to_object(player) > 16)
{
sprite_index = spr_d;
if (spr_flip == true) image_xscale = -1;
else{ image_xscale = 1; }
}