Object's rotation from another relative to forward

I am setting up a combat system and I have a List of GOs surrounding the player, the player has a list of attacks which have various Extreme Left and Extreme Right Angles that define how far the object can be to the left or right in degrees and the attack still connects here is an image if it helps.

Regardless of the code I have now how can I check as an If statement condition that an object is within x left of the center and y degrees right of the FORWARD.

Hey!
This should be everything you need to get yourself going, Link

Without having actually set it up, I imagine you’re going to want to shoot a ray to the surrounding enemies, or enemies that fall within a given range. Such as a overlap sphere. Then using this ray get the angle between it and your players visual radius…etc.

Much luck

I already have the rest of the code, how can I calculate the angle being left or right

You’ll need to incorporate something like this into your current code.
Otherwise, without having the code you’re mentioning…I don’t know?

    protected float AngleBetweenPoints(Vector2 a, Vector2 b) {
        return Mathf.Atan2(a.y - b.y, a.x - b.x) * Mathf.Rad2Deg;
    }

    public bool PointWithinForwardAngleRange(Vector2 point, float left, float right) {
   
        float angle = transform.rotation.eulerAngles.z;

        float relativeAngle = AngleBetweenPoints(point, transform.position) - angle;

        //Convert the rotation to be between -180 and 180 rather than 0 and 360
        if (relativeAngle <= 180f) {
            relativeAngle += 180f;
        }

        //Angles below zero would be to the right of forward
        if (relativeAngle < 0f) {
            return Mathf.Abs (relativeAngle) <= right;
        } else {
            return relativeAngle <= left;
        }
    }

These two functions should do it.

Working example enclosed in a scene as a unity package. If the line coming out of your character pointing to the dummy turns green, it’s within the specified left/right range.

1890149–121628–ForwardAngleRange.unitypackage (20.8 KB)