Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


line of sight

This topic is 5841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i need some info on line of sight for 2d. incase if "line of sight" is something else then what i think it is.. i refer to; my enemyies seeing me only when i am exposed in the open .. and not seeing me when i am behind and object. i did a search on the web but i got very irrevelant hits. so any ideas or resources would be apriciated. thanks

Share this post

Link to post
Share on other sites
Im not sure if this will help, but here goes. First you would have to set up a line of site with your enemies, a triangle or 3d frustrum. The simples(but probably slowest) would be using a series of squares []
[ ]
[ ]

In the above example there are 3 squares, the first one small, the second one long, and the third one longer. You would then use collision detection on those boxes. Finally, if there is a collision, check and see if there is anything between the enemy and the player. If ther is a collision with the player, you must then check and see if there is a collision with at wall. If not, the player sees the enemy. If ther is, you must then see if the left edge of the wall is greater than the position of the enemy and the position of the player, and if the right edge of the wall is less than(assuming you are using a standard coord system where to the right are bigger numbers, left smaller) the position of the enemy and the player. Then there is a wall inbetween them and the player cannot be seen. Other wise, the wall is just beside the player and the player is seen.

I have never actually done this before. I simply saw your post and speculated how it is done, so the wall checking collision may be a little different. But it all should work with minor adjustments

Share this post

Link to post
Share on other sites
dah, didn''t keep spacing those three [] are supposed to make a pyramid type shape.With each one getting larger, i.e: []_____________________________________________________[__]__________________________________________________[________].

Share this post

Link to post
Share on other sites
To elaborate on liquidus4,

Line of sight (LOS) in non-computer game terms mean that you draw a line (on war game tables I''ve seen them use string) form the center of a unit to the center of whatever the object the unit is looking at (ie another unit). If that line is broken in any way, then the unit cannot see the object.

Liquidus4 is taking into effect the other factor of LOS and that is “facing”. LOS should only be calculated if the object the unit is trying to see is in that unit’s arc of vision. Don’t worry; this is simple to figure out. The arc is usually a 45-degree angle from the center of the unit.

Now that said, here are the exceptions you should note. If the object breaking the LOS is a tree, hedge, fence, slight hill, ect.. then a modifier is attached to the equation. Just because the enemy is behind a fence doesn''t mean you can''t see them.. or does it? Fore instance, My artillery is on a hill and your troops are advancing behind a stone wall. The hill would give me a +1 to see you because I can see you over the wall, but the wall itself would give me a -2 because you are crouching behind it. You can also use LOS to figure out combat modifiers.

Now, this is how non-computer games do it.

Is the object my unit is trying to see in my unit’s arc of vision? (facing)
If YES, is the LOS blocked by any object?
If YES, what are the combined LOS modifiers of all objects blocking the LOS?
Is that total less/more than the base amount to see an object?
If YES, the unit can/cannot see the object.

Do you do this for your code? Well you can. Would I?… hmm… I’ll try.

Set up all objects in the game with an (x,y) coords, LOS modifier, and Arc of Vision variables. Yes, that''s right, you better be doing object oriented programming here.


Determine if the object trying to be seen rests in the arc of vision of the unit doing the seeing.
Pass the (x,y) coords of both objects to a function
Set a varriable to be the BaseLOS
Draw a line from center to center of the two objects in question.
Determine if the line collides with any object.
Return the LOS factor of objects the line collides with.
Add up LOS factors returned.
Determine if the BaseLOS has been met or past.
Don’t forget to set a global hit modifier in case you want to shoot at it.

Lastly I’m an artist more than a programmer. Under no circumstances should you take my advice on programming hahaha. I just play a lot of non-computer war games and thought I’d share with you how LOS is determined in those games.

Good luck

"It’s been a very long time since I’ve ceased to be preoccupied with reality."

-Alfred Hitchcock

Share this post

Link to post
Share on other sites
If you want more info, you might check the articles and resources section here on GameDev. I specifically found this line of site article for tile-based games in the Isometric and tile based games section.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!