Find the closest object
by Sam M · in Torque Game Builder · 06/26/2006 (4:26 pm) · 1 replies
Hi everybody.
Ok, so on my latest project i've got a problem figuring out how to implement this one thing. Basically I have a player sprite, and a bunch of other sprites scattered around the scene. All the other sprites are in a class called "Object". What I want is everytime I press one button I can find the closest object to my player on it's right, and when I press another button I can find the closest object to my player on it's left.
Anyone got any ideas on how to find the closest object on a player's left/right? Preferably on that doesn't include naming every single object in the Level Builder.
Thanks alot,
Sam M
Ok, so on my latest project i've got a problem figuring out how to implement this one thing. Basically I have a player sprite, and a bunch of other sprites scattered around the scene. All the other sprites are in a class called "Object". What I want is everytime I press one button I can find the closest object to my player on it's right, and when I press another button I can find the closest object to my player on it's left.
Anyone got any ideas on how to find the closest object on a player's left/right? Preferably on that doesn't include naming every single object in the Level Builder.
Thanks alot,
Sam M
Torque Owner David Guy
Look into the t2dSceneGraph methods pickLine(), pickPoint(), pickRadius() and pickRect(). These should allow you to get a minimal number of objects on either side of your player. If you wind up with more that one object, you could then do a simple distance computation using the console math method t2dVectorDistance().
HTH