Game Development Community

Is it possible to do it with TGB?

by Firas · in Torque Game Builder · 08/24/2006 (6:27 am) · 8 replies

I mean like super mario when the hero collide with the enemy from front or back the hero will be hit, but if the hero jump on the enemy the enemy will be hit.

is it possible to do this with TGB?

#1
08/24/2006 (6:49 am)
Part of the collision callback is the collision normal. By looking at the normals of the objects you can see check which sides of the objects are colliding.
#2
08/24/2006 (10:56 am)
Thanks for respond philip

I have check the TGB referance and found that callback syntax :

onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal,%contacts, %points)

I think you mean the %normal variable is what I nead in my case.

but there is a question:

how to know my objects normals?

thanks in advance.
#3
08/24/2006 (6:28 pm)
Firas, there's always the tested theory of outputting the objects variables to the console and testing it ... otherwise, the TDN docs for licensed users would probably have more descriptive detail.
#4
08/24/2006 (8:07 pm)
Firas, the function to getLinearVelocityPolar will return you the angle and velocity. Which in effect is your players motion vector.
#5
08/25/2006 (4:08 pm)
We tried a different method that works pretty well: get the bounding box of the collision polygon of the player and check it against the bounding box of the enemy collision polygon. You can cache the local coordinates of the collision poly's bounding box during the object's onLevelLoaded callback and then in your onCollision callback you can check if it's an enemy and then use [object].getWorldPoint() to find the world coordinates of the bounding boxes and compare them to see if one is on top of the other. You probably also want to check if the one on top is falling at the time. If I find the code we used I'll post it for you, but in the meantime you get the basic idea.

Good luck!
#6
08/30/2006 (10:31 am)
Guys help
in the onCollision function I was trying to check the %normal value so I was printing it to the consol using the echo command like this:

function playerShip::onCollision(%srcObject, %dstObject, %srcRef, %stRef, %time, %normal,%contacts, %points)
{
echo("the normal is: " @ %normal);
}

and I was having a value like these:
"0.999950 0.009983"

and so on but I don't know how to deal with these numbers to determine is it the top or the bottom of the player?

so colud anyone help me and explain how to deal with these numbers?

thanks in advance
#7
08/30/2006 (10:40 am)
I believe you should try rounding your numbers to the nearest integer and then compare to the following:

Top: "0 -1"
Right: "1 0"
Bottom: "0 1"
Left: "-1 0"
#8
08/30/2006 (12:12 pm)
It work fine

thanks