View Full Version : Line of Sight
darnpunk
January 28th, 2009, 08:41 AM
Hi all,
I've seen and read many articles on the topic above. After reading it, I tried to apply the techniques (e.g. Bresenham's line algorithm) and got good results. In an flat tile-based or continuous environment, the line of sight works great. However, on isometric tile-based environment I face accuracy issues. I applied the same concept (exact same as flat tile based) but due to the perspective there are some problems.
For example, the character and the enemy are in linear view but the projection of the line of sight is not straight (staggered map) and this caused the line to hit something out of the linear view.
I am guessing I need to compensate for the rotated view etc. But I am quite unsure how to begin or if other issues will rise. Does anyone have experience on this and willing to share? How different is a flat tile-based line of sight algorithm from isometric one?
Regards,
darnpunk
rrh
January 28th, 2009, 04:02 PM
It should basically be rotated 45 degrees, then the vertical scale reduced to less than the horizontal scale. Right?
With the original orientation, how well did the line of sight work with diagonal lines?
NJB
January 28th, 2009, 04:34 PM
It should basically be rotated 45 degrees, then the vertical scale reduced to less than the horizontal scale. Right?
With the original orientation, how well did the line of sight work with diagonal lines?
That would be for transforming a square tile to an isometric tile.
using a little hacked apart trig, I came up with this:
x=-1.8305y gives a line at the right angle going from top left to bottom right, and
x=1.8305y gives a line going bottom left to top right.
not sure if this is at all helpful, but it's the best I can come up with at the moment (maths is NOT my strong point)
darnpunk
February 1st, 2009, 09:44 PM
I will give it a try soon. For line of sight, it is ok to use hitTestPoint for each tile I check? For example, I am thinking of using line of sight algorithm to project a line from source to target. Let's say it is a 5 tiles apart. I project a line for every tile and check if it hits anything. Once I reached the 5th tile, if there are not hits I assume line of sight is true. False if I hit anything.
If I have more than 10 tiles, will it be slow for the hit tests? Anyway, I find using hitTestPoint quite inaccurate. I used the HitTest class over here - http://www.tink.ws/blog/as-30-hittest/ and it provides more accuracy except that it gets slower if there are more hits to check.
Lifirenk
May 20th, 2011, 11:58 AM
I am also making a game that requires a line of sight algorithm for enemies. Although my game is not a tile based game and so I seem to be having alot of trouble detecting walls despite trying various methods of wall detection. The game I'm making is a kind of maze type game.
Josh Martin
May 23rd, 2011, 04:53 AM
Hi all,
I've seen and read many articles on the topic above. After reading it, I tried to apply the techniques (e.g. Bresenham's line algorithm) and got good results. In an flat tile-based or continuous environment, the line of sight works great. However, on isometric tile-based environment I face accuracy issues. I applied the same concept (exact same as flat tile based) but due to the perspective there are some problems.
How are you storing the tiles for your game? Can't you simply treat your coordinate system as if it were oritented in line with the cardinal directions (aka, treat up-left as the y-coordinate(+), up-right as the x-coordinate(+), down-right as the y-coordinate(-), down-right as the x-coordinate(-) (or however you have your coordinate space laid out)
If your using Bresenham, you should still get the same results, even if you have non-square tiles. Depending on the art, you may get slightly odd looking lines, but they would be geometrically sound.
PSvils
June 1st, 2011, 09:42 AM
How are you storing the tiles for your game? Can't you simply treat your coordinate system as if it were oritented in line with the cardinal directions (aka, treat up-left as the y-coordinate(+), up-right as the x-coordinate(+), down-right as the y-coordinate(-), down-right as the x-coordinate(-) (or however you have your coordinate space laid out)
If your using Bresenham, you should still get the same results, even if you have non-square tiles. Depending on the art, you may get slightly odd looking lines, but they would be geometrically sound.
This.
I am also making a game that requires a line of sight algorithm for enemies. Although my game is not a tile based game and so I seem to be having alot of trouble detecting walls despite trying various methods of wall detection. The game I'm making is a kind of maze type game.
You should construct your maps with lines, and then you can easily check for intersections and collisions.
P.
dozza92
June 3rd, 2011, 09:20 PM
How are you storing the tiles for your game? Can't you simply treat your coordinate system as if it were oritented in line with the cardinal directions (aka, treat up-left as the y-coordinate(+), up-right as the x-coordinate(+), down-right as the y-coordinate(-), down-right as the x-coordinate(-) (or however you have your coordinate space laid out)
If your using Bresenham, you should still get the same results, even if you have non-square tiles. Depending on the art, you may get slightly odd looking lines, but they would be geometrically sound.
I agree, If your Bresenham's algorithm is based on the tiles in your game rather than the screen coordinates you won't have a problem whether it's isometric or not. If it is based on the screen then the best way to get around that is to make your algorithm work for the tiles rather than the screen. Shouldn't be too much of a difficult port.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.