Search Unity

'looking' script...

Discussion in 'Scripting' started by bomber, Mar 30, 2008.

  1. bomber

    bomber

    Joined:
    Dec 20, 2007
    Posts:
    27
    Hi guys...

    I'm trying to get my head around the script required for an AI turret gunner on a WWII bomber..

    What I need is for the AI gunner to search the sky for planes... not to automatically know when an enemy is near by it's tag... So he must track planes that he doesn't know are friend or foe until he's identified them, probably by being so close, but once he's identified them as friend he can 'forget' about them... until he's forgotten about them for so long that he has to re-identify them again..

    So anyway all I want to start with is a pointer on how to go about making an AI code that 'sectors' up his sky identifying planes, logs them and can't see through objects..

    I've not really explained this very well... :(

    Simon
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    You could divide the sky up using angle ranges of elevation and azimuth. If war films are anything to go by, then you should use twelve sectors in each ("Bandits at 10 o'clock", etc). You can detect if an object is in a sector by pointing a non-rendering camera object at that sector (with field of view set to 30º) and using the methods of GeoemetryUtilities (CalculateFrustumPlanes and TestPlanesAABB). You would then need an array with an element for each sector. Each array element would contain fields counting how many friends or foes were in the corresponding sector.

    The gunner then has to choose a sector of sky to search at each time step. This is semi-random, but the probability of checking a sector should increase proportionally to how many foes it contains. Also, a sector containing only friends should have a lower chance of being chosen - the presence of the friend "explains away" the noise and movement in that sector. The task of choosing items using a biased probability is known as "roulette wheel" selection - genetic algorithm literature is a good place to find out more about this.

    Finally, when the gunner looks at a particular sector, presumably there is a random chance he will detect a given aircraft, depending on how large it is and how far away. You could use raycasting to determine whether an object is obscured by something else that is nearer.
     
  3. bomber

    bomber

    Joined:
    Dec 20, 2007
    Posts:
    27
    Thanks andeeee for reassuring me that there is a way of doing what I want to achieve and pointing me in the direction to look...

    Regards

    Simon