Topic was automatically imported from the old Question2Answer platform.
Asked By
wildcard
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.
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.