T2008
Member
I am trying to make the NPCs face player when player is talking to npc. I made the below script that I run which does 4 diagonal directions. I can't get it to work for all 8 directions. I use the switch statments with all 8 when objects are moving (like enemies). However this doesn't work when enemy/character is not moving. Any help would be greatly appreciated!
Current Script:
Script that works only when object is moving:
Current Script:
Code:
//Player Left and Above NW
if (obj_player.x < x) && (obj_player.y < y) {
sprite_index = stand_nw;
npc_stopped_sprite = stand_nw;
}
//Player Left or Equal and Below or Equal SW
if (obj_player.x <= x) && (obj_player.y >= y) {
sprite_index = stand_sw;
npc_stopped_sprite = stand_sw;
}
//Player Right and Above NE
if (obj_player.x > x) && (obj_player.y < y) {
sprite_index = stand_ne;
npc_stopped_sprite = stand_ne;
}
//Player Right or Equal and Below or Equal SE
if (obj_player.x >= x) && (obj_player.y >= y) {
sprite_index = stand_se;
npc_stopped_sprite = stand_se;
}
Script that works only when object is moving:
Code:
switch ((((direction + 22.5) mod 360) + 360) mod 360) div 45 {
case 0: sprite_index = choose(stand_e,eat_e); break;
case 1: sprite_index = choose(stand_ne,eat_ne); break;
case 2: sprite_index = choose(stand_n,eat_n); break;
case 3: sprite_index = choose(stand_nw,eat_nw); break;
case 4: sprite_index = choose(stand_w,eat_w); break;
case 5: sprite_index = choose(stand_sw,eat_sw); break;
case 6: sprite_index = choose(stand_s,eat_s); break;
case 7: sprite_index = choose(stand_se,eat_se); break;
}