+1 vote

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.

Godot version 3.2.2
in Engine by (26 points)

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?

1 Answer

0 votes

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")
     print("is behind")
if dir.x > 0:
     print("is right")
     print("is left")
if dir.y > 0:
     print("is over the horizon")
     print("is under the horizon")

have not tested the code

by (4,086 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.