How to create 'sections' in a vision cone?

Hi,

I’m currently working on a project where the enemies have vision cones and the design I have is that a single vision cone has three sections to it. The full length of the vision cone is 15 metres and split in three like so; 0-5, 5-10, 10-15.

My vision works at the moment by using a cone shaped mesh collider and when triggered by the player the enemy will chase. I was wondering how I go about splitting my vision cone up into 3 ‘sections’? I have a feeling that I need to use Vector3.Distance (I’m unsure of this route however) or I could make 3 individual vision cones (which would be the long way round probably).

Any help/direction would be appreciated.

If you use Vector3.distance, your vision cones will have a rounded base (wich may be what you want). It’s not a bad solution but the script may be a mess quickly if you have very specific behaviour according to the section of the vision cone.

Otherwise, if you use a trigger as vision cone, splitting it in 3 may be a good solution. Each section will have it’s own script with a different behaviour. Then, you could use an abstract class VisionCone and three sub classes as follow :

public abstract class VisionCone : MonoBehaviour
{
    // Drag and drop the closest vision cone here
    public ClosesVisionCone ClosestVisionCone ;

    // Drag and drop the middle vision cone here
    public MiddleVisionCone MiddleVisionCone  ;

    // Drag and drop the farestvision cone here
    public FarestVisionCone FarestVisionCone ;

    private void OnTriggerEnter(Collider other)
    {
        Foo(other) ;
    }

    protected abstract void Foo(Collider other) ;
}

public class ClosestVisionCone : VisionCone 
{    
    protected override void Foo(Collider other)
    {
        Debug.Log("Closest") ;
    }
}

public class MiddleVisionCone : VisionCone 
{    
    protected override void Foo(Collider other)
    {
        Debug.Log("Middle") ;
    }
}

public class FarestVisionCone : VisionCone 
{    
    protected override void Foo(Collider other)
    {
        Debug.Log("Farest") ;
    }
}

Then, you will have to drag and drop the appropriate script on the appropriate section of your vision cone.

Splitting an object in 3D is not that hard. In Blender for example, you have the Loop Subdivide tool :

http://www.blender.org/manual/modeling/meshes/editing/subdividing/loop_subdivide.html?highlight=loop