BGE: Create a sight system for an enemy
Because the radar sensor finds all objects within its distance cone, it will return all objects, even ones hidden behind others.
To find only the "visible" objects, I'm checking that a ray can go from the radar object (the object with the Radar sensor logic) to each of the detected objects with rayCastTo.

This script loops through all the objects that the Radar sensor detects, and casts a ray to each of the objects. (Think of it as shining a laser   towards each of the detected objects, if the laser hits the object then the radar object can see it, if some other object is in the way, then it is blocked and it is hidden.)

import bge

cont = bge.logic.getCurrentController()
own = cont.owner

radar = cont.sensors["Radar"]

for obj in radar.hitObjectList:
    if obj is own.rayCastTo(obj, radar.distance):
        print(obj)


Line 9 is where the magic happens: own.rayCastTo(obj, radar.distance):.
That function starts the ray at the radar object, own. Then the first argument obj is the object that the ray is pointing towards. The last argument radar.distance is how long the ray will be, here I am using the distance set in the radar sensor, so the two will always be the same length.

All you need to do is connect this script to a Radar Sensor as shown below.