Game Development Community

How to parse the result of CastCollision

by Teddy Setiawan Wijaya · in Torque Game Builder · 10/02/2006 (1:55 am) · 6 replies

Hi All!

A newbie question here....;-(

Does anyone have example code on how to parse the result of castCollision?

I've read in the reference that castCollision returns a list in the form of "object time contact normal", where object is the object to be collided with.

How do I get the object name from this list?

Many thanks,

#1
10/02/2006 (2:03 am)
%result = %obj.castCollision(0);

 %object = getWord( %result, 0 );
 %time = getWord( %result, 1 );
 %contact = getWords( %result, 2, 3 ); // these are vectors
 %normal = getWords( %result, 4, 5 ); // ----

Hope that helps.
#2
10/02/2006 (3:16 am)
Michael, thank you for the response.

After I get the object id (for example: 2829), how do I get the object name?

I have tried using

if (%object == nameToID("frontDoor"))
{
   // some code here
}


but it doesn't seem to work (the response seems to be always false)

Thanks again,
#3
10/02/2006 (3:32 am)
Try %object.getName().

And strings have to be compared with the '$=' operator, not '=='.
#4
10/02/2006 (6:48 am)
%frontDoor = frontDoor.getId();
error("object: " @ %object);
error("frontDoor: " @ %frontDoor);
if (%object == %frontDoor)
{
   // blah
}
Run this code and check out the console. You should see in red the ids of both objects. Make sure they actually are equal as you expect them to be.
#5
10/02/2006 (1:05 pm)
Speaking of castCollision... I don't think it's working properly: www.garagegames.com/mg/forums/result.thread.php?qt=50707
#6
10/03/2006 (1:57 am)
Ben, Michael,

Thank you for the information, I use %object.getName() as told by Michael and compare it with the object name (frontDoor) using $=

Works for me...;-)