problem with onCollision for each object [solved]
by Rami Bokhari · in Torque Game Builder · 05/24/2011 (7:26 am) · 8 replies
hey guys, what am I trying to do is to control the nCollision with specific objects..
I did :
this code is not working! any help? I know it's a noob question am sorry XD
I did :
function platform::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
%classy = %srcObj.getClassName();
if(%classy $= "bullet")
{
alxPlay(ShrekenWallHit);
}this code is not working! any help? I know it's a noob question am sorry XD
About the author
I love video games.. video games are my life.. playing can't satisfy me anymore.. thank you GG helping me making my dream worlds a reality
#2
05/24/2011 (8:12 am)
thanks, but the problem is I don't want everything hit with the bullet play SFX I need to control it...
#3
Which part of it does not work? onCollision is not called, or %classy variable is empty, or alxPlay doesn't play anything? It shouldn't be hard to find where it does something you don't want it to.
05/24/2011 (9:55 am)
Oh, I've got it wrong...Which part of it does not work? onCollision is not called, or %classy variable is empty, or alxPlay doesn't play anything? It shouldn't be hard to find where it does something you don't want it to.
#4
it seems the problem was in getClassName()function
thanx again Rpahut :)
05/24/2011 (10:33 am)
thanx man.. I did this and it workedfunction platform::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
if(%dstObj.class $= "bullet" )
{
alxPlay(ShrekenWallHit);
}
}it seems the problem was in getClassName()function
thanx again Rpahut :)
#5
09/27/2013 (7:07 pm)
I think "isMemberOfClass()" function would work, I think. So you could say...function platform::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
if(%dstObj.isMemberOfClass(bullet))
{
alxPlay(ShrekenWallHit);
}
}
#6
09/27/2013 (7:12 pm)
And be mindful that %srcObj and %dstObj are not guaranteed to be in any given order. Either one could be the one that is hit or the one hitting, if you take my meaning....
#7
09/28/2013 (5:59 pm)
Also, wouldn't %this have to be added to the function-parameters for "platform"?
#8
You can set up scoped functions that don't rely on an underlying object - in which case the first parameter is not special in any way.
09/28/2013 (7:56 pm)
If "platform" is an object then sure - however, depending on how the system is ordering collisions %srcObj might actually be %this anyway.You can set up scoped functions that don't rely on an underlying object - in which case the first parameter is not special in any way.
Torque Owner Rpahut
function bullet::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points) { alxPlay(ShrekenWallHit); }