How do you know on which side relative to the player the enemy is on in 3D?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wildcard

Let's say I have the following setup:

I want to be able to know if an enemy is either in the top-left quarter of the local space relative to the player, or the top-right one.
How would I go about doing that?
I’ve tried doing degrees but there is no defining criteria to differentiate between local left and right in that case.

First “left/right” is only applicable to the 2D basis.
Second, it also requires to compare directions.

Can you post a picture of your task?

sash-rc | 2021-09-01 15:08

:bust_in_silhouette: Reply From: klaas

Hi,
if you calculate a direction vector to the enemy

var dir = to_local(the_enemy.global_transform.origin).normalized() #direction to enemy
if dir.z > 0:
     print("is in front")
else:
     print("is behind")
if dir.x > 0:
     print("is right")
else:
     print("is left")
if dir.y > 0:
     print("is over the horizon")
else:
     print("is under the horizon")

have not tested the code

So, my task is to make a system that would help my IK to find targets that are actually ok to target (so no weird hand twists or stuff like that) and the way I’m trying to implement it right now is just to have 2 (technically 3) areas attached to the player and just keeping track of enemies in them through code and signals.

I know you can't tell much, but the player's left hand if being rotated so that it points to the object on the right

Hope that’s enough to grasp what I’m dealing with

wildcard | 2021-09-02 06:29