The Daily Click ::. Forums ::. Klik Coding Help ::. Line of sight?
 

Post Reply  Post Oekaki 
 

Posted By Message

blubblub



Registered
  29/02/2012 23:35:38
Points
  14
11th March, 2012 at 11/03/2012 16:48:51 -

Hello

Is there any other good way to make line of sight, besides the one where you 'draw' a line of sight detector between the objects?

 
n/a

nivram



Registered
  20/07/2006
Points
  171
11th March, 2012 at 11/03/2012 23:00:59 -

On my website there are examples, plus in the Technical Manual under Design there is a section on Line of Sight.

Marv

 
458 MMF2 & CTF 2.5 examples and games

http://www.castles-of-britain.com/mmf2examples.htm

blubblub



Registered
  29/02/2012 23:35:38
Points
  14
12th March, 2012 at 12/03/2012 12:41:40 -

Which one would that be?

 
n/a

nivram



Registered
  20/07/2006
Points
  171
12th March, 2012 at 12/03/2012 16:32:20 -

One is "Chase When Seen Example"

Marv

 
458 MMF2 & CTF 2.5 examples and games

http://www.castles-of-britain.com/mmf2examples.htm

blubblub



Registered
  29/02/2012 23:35:38
Points
  14
12th March, 2012 at 12/03/2012 17:13:58 -

Well that one uses the exact method i don't wanna use.

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
12th March, 2012 at 12/03/2012 20:33:31 -

Why not?
It's a very simple and efficient method - if you expect someone to figure out a different method, you'd better explain what's wrong with it.

 
n/a

Carnivorous id



Registered
  03/04/2008
Points
  957
12th March, 2012 at 12/03/2012 20:52:02 -

Thanks nivram I was trying to figure out line of sight. Just saved the link to your site as well.

 


Image
More Carnivorous iD games info @ https://www.facebook.com/carnivorousid/?ref=bookmarks

blubblub



Registered
  29/02/2012 23:35:38
Points
  14
12th March, 2012 at 12/03/2012 21:13:44 -

It's buggy sketchy.

I'll use your example for demonstration, one second.

Edit:

http://i.imgur.com/sBbHJ.png

If you are directly below or above the object the 'line' becomes too thin and isn't displayed. Now you can do a workaround by making the line 2x2 pixels instead of 1x1. But then it overlaps the backgrounds in some situation where it shouldn't. IE the enemy is one field above and one to the right of you. At least in my game it is like that. I use a grid movement.

Also it doesn't seem to work if the enemy is off the screen.

Edited by blubblub

 
n/a

SolarB



Registered
  26/12/2011
Points
  564
13th March, 2012 at 13/03/2012 01:10:05 -

I'm trying to get LoS in my game using Sketchy's example but it grinds everything to a massive halt when there are 50+ enemies/players all with shoot-if-distance < x conditions running around... I wish I could implement it but I may have to let it go and just have my units look stoopid firing into walls and such.

 
My Open Source Examples: http://bit.ly/YyUFUh

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
13th March, 2012 at 13/03/2012 01:59:41 -

@Blubblub -
Where are the hotspots on those objects?
If they're in the top-left corner, there *is* a clear line of sight, because the blue object is not properly aligned to the grid. Either way, you should *always* put the hotspot in the centre of the object when checking line of sight (or use the action point instead, and put that in the centre).

Which example is that anyway?
There are two basic ways of doing it:

A. Have a small detector, and move it step-by-step from A to B - it's potentially buggy and may miss collisions if the step is too large; you can check for the exact point at which the line of sight is broken; it's slow, but may be faster than the alternative if you're not using HWA (especially if you use larger steps).

B. Stretch and rotate a detector to form a line - if you're using HWA it's very fast, but it may be slow if you're developing for Flash/iOS/etc which don't benefit from HWA; it gives 100% accurate, bug-free results; it only tells you *if* the line of sight is broken, not *where*.

C. MMF2 also has a built-in feature to check for a line of sight, but it's still too buggy to use really
https://skydrive.live.com/redir.aspx?cid=b1e7ee094271bbda&resid=B1E7EE094271BBDA!499&parid=B1E7EE094271BBDA!131&authkey=!

I always use method "B", but with embedded detectors:
https://skydrive.live.com/redir.aspx?cid=b1e7ee094271bbda&resid=B1E7EE094271BBDA!480&parid=B1E7EE094271BBDA!131&authkey=!


@Noodles -
100+ objects certainly shouldn't be a problem with HWA. If you're using Flash / iOS exporters, you might be better off using the other method, but it'll probably still be slow.
If you have many enemies and many players, using ForEach loops instead of fastloops will make a big difference. Also, make sure you only resize the detector after checking the distance/angle (and keep the maximum shooting distance quite small).

Edited by Sketchy

 
n/a
   

Post Reply



 



Advertisement

Worth A Click