how can I detect if an entity is moving away from me ?
Write a state machine for your monsters, such that they have multiple "states": wander, wait, hunt, attack, retreat. If the monster is retreating or something, then we can automatically assume that he's trying to move away

inside a 3D space I want my enemies only to attack when they can see you (when they are facing you) . so how can I calcutate something like this ?
Have the enemies perform a c_scan instruction with a wide arc and a long distance. If they detect the player (use event_scan for this), have them perform a c_trace instruction to trace an invisible line from themselves to the player. If the line doesn't hit anything (ie they have a direct line of sight to the player), then they can go to "attack" mode or something.
I hope that helps
