Field of Vision

I’m creating a Stealth Artefact for university, where the stealth AI is pretty much the same as Metal Gear Solid.

Since doing this, I am trying to visualize the enemies sight within the editor so it’s easier for me to plan the layout etc.

I am currently using this to ‘draw’ a field of view.

    void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Vector3 direction = transform.TransformDirection(Vector3.forward) * 5;
        Gizmos.DrawFrustum(transform.position, 45.0f, 10.0f, 0.0f, 1.0f);
        //Gizmos.DrawRay(transform.position, direction);
    }

But in the editor, this is what I’m seeing with the frustum that I’ve used.


The frustums always seem to lock into the centre of the world.
Is there a way to change this, or another method to visualize a field of view?

I suspect the issue is this part from the scripting reference:

Try assigning different stuff to Gizmos.matrix to see if it gets the desired behavior, such as:

        Gizmos.matrix = transform.localToWorldMatrix;

The less-technical solution would just be to attach a child object to each enemy that looks like a semi-transparent cone pointed in the correct direction. (And toggle on/off as appropriate.)