Hi all, I have been working on something base on MrMcFlurry's article partly about making a line of sight system for AI (http://www.create-games.com/article.asp?id=2137). I have every thing working so I'm trying to optimize the code but I still getting lots of slow down when their are too many bad guys in the frame. Right now I can have about 15 objects with line of sight but if I add one or two more my FPS falls off a cliff! 15 or so bad guys wouldn't be bad but I wanted to use the TGF2 New Grounds Edition and build it as a SWF but when I do that I can only add around 5 objects before it becomes unplayable and that's just not enough to make the game I want. I know their would be some slow down using SWF but according to the article I should be able to have around 50 line of sight objects before slow down when building as and EXE and I only need 10-15 objects at one time.
What I have done is almost exactly what the article says but instead of using the direction calculator object I have done all the calculations myself in the expression editor.
I'm using the flowing to find the angle:
I was wondering if any one could take a look over my code and tell me if their is any thing I can do to help improve the speed. I would hate to just have to abandon it
Never mind. I just found out what the problem was. I changed the LOS pixel (called "BadGuyLOS" in the code BTW) to be 2x2 so I could see it better while I was debugging. If i set it back to 1x1 the speed of resizing more than doubles, wow! Now I can have over 20 Bad guys before the speed drops down to less then 25 fps, problem solved! Who would have thought 3 pixels could make that big a differences?
Even with the problem fix I would still be nice to get this thing moving as fast a passable so if anyone can take a look and give me some ideals that would be great!
I talking to my self here but another to speed up this system is only set the range and angle LOS objects with even spread values one frame and then the odd one on the next frame using the mod operator. You lose a little accuracy but double your frame rate!