Calculating "real" distance between sceneObjects
by James Ford · in Torque Game Builder · 03/20/2008 (8:17 pm) · 3 replies
I would like to know the "real" distance between two t2dSceneObjects, taking into account both object's collision areas.
Does functionality to perform this already exist somewhere in the engine?
Something like a raycast from the source object's center against the destination object and returning the collision info -- this would at least take into account the destination object's collision area, not sure how to add in the source object's as well.
TGB doesn't seem to have any "external" raycast functions ( pickLine returns objects but no positional information ).
It seemed like I might be able to use the t2dPhysics method castLine ( which is used internally by pickLine ), but it doesn't collect positional info either.
t2dPhysics::calculateCollision looks like it does the positional calculations that are later returned in script oncollision callbacks, so perhaps I could leverage that... but not sure how to go about it.
Maybe I'm going way overboard looking for a solution here... I could after all use the unit's "size" field, but this still requires customization depending on if the object's collision is circular ( calculate a radius ), or full ( have to look at the rotation too? )...
I would love to hear from anyone who has messed with this area of TGB, or something obvious I missed.
Does functionality to perform this already exist somewhere in the engine?
Something like a raycast from the source object's center against the destination object and returning the collision info -- this would at least take into account the destination object's collision area, not sure how to add in the source object's as well.
TGB doesn't seem to have any "external" raycast functions ( pickLine returns objects but no positional information ).
It seemed like I might be able to use the t2dPhysics method castLine ( which is used internally by pickLine ), but it doesn't collect positional info either.
t2dPhysics::calculateCollision looks like it does the positional calculations that are later returned in script oncollision callbacks, so perhaps I could leverage that... but not sure how to go about it.
Maybe I'm going way overboard looking for a solution here... I could after all use the unit's "size" field, but this still requires customization depending on if the object's collision is circular ( calculate a radius ), or full ( have to look at the rotation too? )...
I would love to hear from anyone who has messed with this area of TGB, or something obvious I missed.
About the author
http://jamesdev.info
#2
03/25/2008 (8:48 am)
Nifty James ... I can see how that might come in handy. Thanks for the resource!
#3
You may also want to take a look at the script function "castCollision." With some clever scripting, I've used it in the past for determining "exact" distances between scene objects.
03/25/2008 (1:04 pm)
James, You may also want to take a look at the script function "castCollision." With some clever scripting, I've used it in the past for determining "exact" distances between scene objects.
Associate James Ford
Sickhead Games
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=14481