The Daily Click ::. Downloads ::. Engine ::. Line of Sight (LoS) Engine
 

Line of Sight (LoS) Engine
Author: Sketchy Submitted: 8th January, 2009 Favourites:0
Genre: Engine Downloads: 329
Rated:


Based on this article by Destroyer (Crobasoft):
http://www.create-games.com/article.asp?id=1761

Big thanks to jneumann1 for his help and encouragement.

------------------------------------------------------------


This is a system to calculate whether a clear line of sight exists between objects.

It is designed primarily for use in stealth-based games, where the player must avoid detection by multiple enemy units.

I have included "cone-of-vision" objects. These are not part of the engine itself - they are merely there to demonstrate that it works as it should. This engine does not use any kind of "detector" objects.

It can handle a large number of objects with minimal slowdown - on my 700mhz pc, using HWA, it runs at a steady 50fps with about 275 enemy objects on screen (with the cone-of-vision objects removed).

The engine is easily customizeable, and all lines are commented.

Requires Advanced Direction extension.

Review This Download



 


http://cid-b1e7ee094271bbda.skydrive.live.com/self.aspx/Public/myLoS.mfa (50.11 kb )



Posted by columbo borgi :C 9th January, 2009

windows live ;*-C
 
Posted by OMC 9th January, 2009

Hmmm. I'd download this if I had MMF2.
 
Posted by ben mercer 10th January, 2009
Rated :

This is a good demonstration on the method of line of sight but it is less efficient than it could be and not hugely extensible. For example the los loop doesnt stop when an obstacle is encountered. Using the collision mask may work for stationary background obstacles but it won't work for moving objects such as doors.

A better way to do this is to forget about fastloops and instead use the move safely 2 object to detect between two points. Its a lot faster and easier too. Of course you will still need fastloops to select each enemy for testing but if you're clever you can alternate the enemies being tested to make it run even faster (i.e. a different 20% of enemies are tested one frame, meaning each individual enemy is only tested every 5 frames).
 
Posted by Sketchy 11th January, 2009

Thanks for your suggestions - I agreee with a lot of what you're saying.
It would be more efficient if it didn't run fastloops for every enemy, and all the way to their maximum range.

It wouldn't be that hard to make it use detectors instead of the collision mask though. Alternatively, for things like doors, you can easily use "add backdrop" and "destroy backdrop at" when they are closed/opened.

Your suggested method, is actually more or less how I started out making a LoS engine - not checking every enemy every frame. It's not really my idea of fast or efficient if it's taking 5 frames just to check LoS though.


 
Posted by ben mercer 11th January, 2009
Rated :

I don't think you've got the point of why you distribute across several frames. It is very much more efficient than testing every enemy, every frame.

It doesnt take 5 frames to actually perform the line of sight test, it still only takes 1. But it means that only a fraction of enemies will be tested each frame.

For example if you have 50 enemies on screen and you distribute across 5 frames, then instead of testing 50 enemies every frame (which would kill your processor), you are testing 10 enemies.

The difference when you use this method is that the algorithm is 500% more efficient. The only drawback is that the enemies may not react instantly, but the maximum reaction delay is 5 frames, which is 1/10th of a second- which is barely noticable.
 
Posted by Sketchy 11th January, 2009

No, I understand, it's just that sometimes 1/10th of a second is quite noticeable - ask an olympic sprinter. Clearly it's not "killing the processor" if it can handle that many objects on even an ancient computer that's too slow to run most click games.
Comment edited by Sketchy on 1/11/2009
 
Posted by ben mercer 12th January, 2009
Rated :

Mmm although I'm not sure how computer games are analagous to olympic sprinting!
 

 



Author

Favourite



Advertisement

Worth A Click