> > There are many ways to go about it but... for the most basic way:
> > What I would do is get the angle from the npc to the player.
> > You can then set the npc frame to round(angle/45). Set frame 0 to be facing east, frame 1 to be facing south east and so on.
> > Does this make any sense?
> Quick code insight, range is a circle sprite pinned to my player object. I use it to detect range as line of sight is useless ^_^
> Here is what I have done http://i.imgur.com/q9AVqRr.png and honestly it is the only way I can think of to actually get this to work. I'm useless when it comes to angles honestly. It works until I added in the part about playing animations, it will not play the animations in the section I highlighted in red... Also if I add in another enemy object only one of them will update. I will need it to update with multiple...
> Can anyone offer insight please? Or perhaps tell me what I am doing wrong.. Any help is greatly appreciated.
> Thanks in advance!
ruskul gave you a great answer..
set a variable on your enemy to round(angle(enemy.x,enemy.y,player.x,player.y)/45)
if this variable is 0 or 8 set animation to east
1 = southeast
2 = south
and so on..
instead of your detection sprite you could check the distance between your enemy and player with distance(enemy.x,enemy.y,player.x,player.y)
I didn't know it was an answer to my problem. But I have a couple questions, again I am new sorry. I set a variable to round(angle(enemy.x,enemy.y,player.x,player.y)/45) but how exactly do I set the rest up? Do I use:
use distance(enemy.x,enemy.y,player.x,player.y) to determine distance
If within distance use round(angle(enemy.x,enemy.y,player.x,player.y)/45) to get the angle
then a big if statement with all the individual possible outcomes?
I have also run into the same problem as before, NE, N, NW do not work