This code will let you fustrum cull your looking entity's field of vision so that it only sees in front.
It's also a good idea where you have multiple enemies looking out for each other to use EntityDistance to organize them into a near to far que so that you're checking the most likely targets first.
Another thing you can do to speed things up is to limit the number of entities you are allowing to look around per frame and give them direct access to the positional information of the last enemy they sighted, between look arounds. I currently only allow one AI to look around per frame and I average about 2 EntityVisible calls per frame with a good reaction speed from the AI's with 30 of them running around in a small arena (at 80 frames per second).
TFormPoint EntityX# ( the_enemy_to_look_for_entity_handle ), EntityY# ( the_enemy_to_look_for_entity_handle ), EntityZ# ( the_enemy_to_look_for_entity_handle ), 0, your_looking_characters_entity_handle If Abs ( ATan2# ( TFormedX# (), TFormedZ# () ) ) < 40.0 Then If Abs ( ATan2# ( TFormedY# (), Sqr# ( ( TFormedX# () * TFormedX# () ) + ( TFormedZ# () * TFormedZ# () ) ) ) ) < 35.0 ;EntityVisible check goes here. EndIf
It's also a good idea where you have multiple enemies looking out for each other to use EntityDistance to organize them into a near to far que so that you're checking the most likely targets first.
Another thing you can do to speed things up is to limit the number of entities you are allowing to look around per frame and give them direct access to the positional information of the last enemy they sighted, between look arounds. I currently only allow one AI to look around per frame and I average about 2 EntityVisible calls per frame with a good reaction speed from the AI's with 30 of them running around in a small arena (at 80 frames per second).