Create Field of vision

Hello devs,

I’m trying to make a field of vision for a basic Artificial Intelligence. I’m just having trouble with the rotation part.
I used “DrawWireDisc” to get a debug.

viewRadius=5;
Handles.DrawWireDisc(tr.position, tr.forward, viewRadius);

Vector3 angle1 = new Vector3(Mathf.Sin(viewRadius * Mathf.Deg2Rad), Mathf.Cos(viewRadius * Mathf.Deg2Rad), 0);
Vector3 angle2 = new Vector3(Mathf.Sin(viewRadius * Mathf.Deg2Rad), Mathf.Cos(viewRadius * Mathf.Deg2Rad), 0);

Handles.DrawLine(tr.position, tr.position + angle1 * viewRadius);
Handles.DrawLine(tr.position, tr.position + angle2 * viewRadius);

The problem is that when the angle is changed when I change the rotate.y instead of the rotate.y
As the game is 2d I just do the rotation for y.

What am I doing wrong?

(In the images I change the rotation in y. And the opening of the angles does not move.)

89280-rotate.png
89281-rotate2.png

Hello

Fix: Unity - Scripting API: Transform.eulerAngles

public Vector3 DirFromAngle(float angleInDegrees, bool angleIsGlobal)
{
    Transform tr = GetComponent<Transform>();
    angleInDegrees -= tr.eulerAngles.z;
    return new Vector2(Mathf.Sin(angleInDegrees * Mathf.Deg2Rad), Mathf.Cos(angleInDegrees * Mathf.Deg2Rad));
}

Use function:

Vector2 viewAngleA = iconViewController.DirFromAngle(-iconViewController.viewAngle / 2, true);
Vector2 viewAngleB = iconViewController.DirFromAngle(iconViewController.viewAngle / 2, true);

Handles.DrawLine(tr.position, new Vector2(tr.position.x, tr.position.y) + viewAngleA * iconViewController.viewRadius);
Handles.DrawLine(tr.position, new Vector2(tr.position.x, tr.position.y) + viewAngleB * iconViewController.viewRadius);

Font: Field of view visualisation (E01) - YouTube