Game Development Community

PickLine and tilemaps

by Hans Sjunnesson · in Torque Game Builder · 09/02/2005 (2:51 pm) · 9 replies

I was wondering if it's possible to restrict pickLine so that it doesn't pass through blocking tiles in a tilemap.

--
Hans

#1
09/02/2005 (3:02 pm)
You can uses masks (like the collision masks) when calling the pick functions.
#2
09/02/2005 (3:23 pm)
Hmm, okay. I'm not really sure of how to use that.
I'll give you an example

img141.imageshack.us/img141/144/screenshot003000027lw.png

In this example the red guys are trying to get to the blue guys. The red guys are currently using pickRadious to determine if there are any blue guys close to them. However, the guys in the middle room are naturally trying to run through the wall to get to the blue guys. Can you use layer masks to restrict pickRadius and pickLine from picking objects which are occluded by the black tiles with their collision polygons filling the entire tile?

--
Hans
#3
09/02/2005 (3:35 pm)
PickLine(%x, %y, %layerMask, %groupMask);


so if the tiles were layer 5 and group 5

pickLine(%x, %y, BIT(5), BIT(5));

you can use globals to store the masks in just like collision masks too :)
#4
09/02/2005 (4:00 pm)
Hmm, I'm not so sure about that. The proper syntax for for pickLine, yanked from the source is:
Quote:
fxSceneGraph2D::pickLine(start x / y, end x / y, [groupMask], [layerMask], [showInvisible?] ) - Picks objects intersecting line with optional group/layer masks.")
Now, the reference docs says that the group and layer masks are for excluding your search to just those groups or layers, but that doesn't mean that T2D calculates visibility through a tilemap by handing it a layerMask.
I ran some tests and checked through the source, and it is quite possible that I missed something - I am pretty tired - but layerMasks isn't the solution, I think. The layerMask is only for restricting the picked objects (which are the blue guys, not the tileLayer) to a certain layer.

--
Hans
#5
09/02/2005 (4:36 pm)
I think what Matt is suggesting is to do a visibility test with pickLine. If you pick the line from the redguy to the blueguy with a mask that only includes the tiles, you will be returned a list of objects between the redguy and blueguy. If there are any, than the redguy can't see the blueguy.

So, do the radius search, then do the pickLine search to see if anything is blocking the visibility to the found objects.
#6
09/02/2005 (4:44 pm)
@Adam: Exactly... sorry I couldn't be more specific, at work so on and off the net :)
#7
09/02/2005 (8:20 pm)
Shouldn't that just be pickRay instead of pickLine?
#8
09/02/2005 (8:33 pm)
In 1.02 pickRay was replaced with the pickLine command... same command just friendly name to game scripters
#9
09/03/2005 (2:05 am)
Quote:
I think what Matt is suggesting is to do a visibility test with pickLine. If you pick the line from the redguy to the blueguy with a mask that only includes the tiles, you will be returned a list of objects between the redguy and blueguy. If there are any, than the redguy can't see the blueguy.

So, do the radius search, then do the pickLine search to see if anything is blocking the visibility to the found objects.

But pickLine won't pick the individual tiles, it will just pick the entire fxTileLayer2D and return it. What's needed, for this to be simple resolved, are more pick methods to the fxTileLayer2D. Right now there's just the equivalent of pickPoint, in pickTile. Having, say, pickTileLine, which would return a vector of tileX/Y, would make my life much easier.

Edit: As an addendum, I guess it wouldn't be too hard to take steps through the tileMap. When you know the tile sizes for that tileLayer, and you know the angle between the start and end points, you know how long the steps ougth to be so you don't over-step into another tile.

--
Hans