Game Development Community

PickArea

by Jeff Trier · in Torque Game Builder · 08/04/2005 (8:06 pm) · 5 replies

Hi all,

For the life of me I can't figure out how to check the area around my player for other objects.

I am giving PickArea a go, as it sounds like that is what I should be using.

Here is what I have done:

...

   // get players position
   %pos = $player.getPosition();
   %x = getWord(%pos,0);
   %y = getWord(%pos,1);

   %detected = t2dSceneGraph.pickArea(%x-1 SPC %y+1,%x+1 SPC %y+1);
...

This of course doesn't seem to work... and I am not sure why (I am sure I am being a bone head).

I checked the Doc's regarding this command, and I seem to have all of the manditory parameters in place.

Any help would be great!

Thanks,
-Jeff

About the author

Originally a Classical/Metal musician, I've always been attracted to anything involving computers, including: Networking, PC Building and Repair, software design and coding. I've been involved with game design and development for over 10 years.


#1
08/04/2005 (8:45 pm)
Are you by chance wanting pickRect()? I don't seem to recall a pickArea() command in the pdf reference doc.
#2
08/04/2005 (9:37 pm)
PickArea is on page 26 of the reference Docs.

pickArea()

Picks objects that intersect specified area
with optional group/layer masks.

(start x /y,end x /y,[groupMask ],[layerMask ],
[showInvisible?] ))

start x/y  Top/left world position of area.

end x/y  Bottom/right world position of area.

groupMask  Selects the group(s)to search for (default is all groups).

layerMask  Selects the layer(s)which to search within (default is all layers).

showInvisible? Specifies whether to include invisible objects in the pick.Default is false.

NOTE:-The result will be a list of objects which satisfy the criteria above and overlap the
specified area.The result is a string of object IDs separated with spaces.The order list is
sorted by layer order from front backwards.

Hmm... I can't seem to find PickRect() ...
#3
08/05/2005 (4:59 am)
It changed from "pickArea" to "pickRect" in the v1.0.2 release.

Youe code would only work if your object is 2x2 in size but there seems to also be a mistake in your code when you're specifying your min coordinates. Surely you meant "%x-1 SPC %y-1" instead of "%x-1 SPC %y+1"?

If you want to pick using the objects size you can do this...

// Get Position.
%x = $player.getPositionX();
%y = $player.getPositionY();
// Get Size.
%hw = $player.getSizeX() * 0.5f;
%hh = $player.getSizeY() * 0.5f;
// Do the pick.
%objs = myScene.pickRect( %x-%hw SPC %y-%hh, %x+%hw SPC %y+%hh );

I will mention that there's some cool stuff in the next release to make this even easier though. You'll be able to make the above easier to understand by using...
%objs = myScene.pickRect( $player.getAreaMin(), $player.getAreaMax() );

You'll also be able to do...
%objs = obj.pick();
... which will return any objects that coincide with the objects collision bounds.

EDIT: Just thought I'd add that apart from the new code I mention in the update, the area doesn't take into account any rotation of the object. This is where the "obj.pick()" has an advantage.

Hope this helps,

- Melv.
#4
08/05/2005 (5:16 am)
You are using an old version of the docs. pickArea() was the original command. In 1.0.2 the commands are pickLine(), pickPoint(), pickRadius() and pickRect(). Not using those commands I'm not sure what actually happens in 1.0.2 if you call pickArea(). However, if it just calls pickRect() you code as given won't work. Maybe its just a typo, but you aren't referring to opposite corners, you do %y + 1 in both cases.

// This is wrong, it picks the lower left corner
%detected = t2dSceneGraph.pickArea(%x-1 SPC %y+1,%x+1 SPC %y+1);
// This is correct
%detected = t2dSceneGraph.pickArea(%x-1 SPC %y-1,%x+1 SPC %y+1);
#5
08/05/2005 (2:10 pm)
Thanks guys,

Just before I went to bed last night I realized I had the coords wrong (I knew I was being a bone head).

I did ended up using pickArea, and it works rather well. Though, I should grab the latest build of the engine and convert the function to PickRect.

Thanks again for all your help!
-Jeff