onCollision Callback
by Bruno · in Torque Game Builder · 10/22/2009 (9:08 pm) · 4 replies
Hi,
I must be doing something terrible wrong here, but i can't spot what.
The Callback is never called, and i'm 100% sure the colision is working.
So, i create 1 sprite like this :
[src]
$spr[%i] = new t2dStaticSprite() { scenegraph = MySceneGraph; };
$spr[%i].setLayer( 13 );
$spr[%i].setCollisionMasks(BIT(2),BIT(13));
$spr[%i].setCollisionActive(true,true);
$spr[%i].setCollisionCallback( true );
// $spr[%i].setCollisionPhysics(false, false);
$spr[%i].setGraphGroup(1);
[/src]
The second sprite, pretty much the same thing :
[src]
$myimages[%x,%y] = new t2dStaticSprite() { scenegraph = MySceneGraph; };
$myimages[%x,%y].setLayer( 14 );
$myimages[%x,%y].setCollisionMasks(BIT(1),BIT(14));
$myimages[%x,%y].setCollisionActive(true,true);
$myimages[%x,%y].setCollisionCallback( true );
// $myimages[%x,%y].setCollisionPhysics(false, false);
$myimages[%x,%y].setGraphGroup(2);
[/src]
If i uncomment the setCollisionPhysics, i see them coliding as they start pushing eachother when moving
one agaisnt the other.
I really don't need physics here, i just need to know if they touch eachother, so i use the callback, like this :
[src]
function sceneWindow2D::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
echo("hereee");
}
[/src]
But nothing happens, no colision whatsoever.
Can anyone see what am i doing wrong here ?
thanks,
Bruno
I must be doing something terrible wrong here, but i can't spot what.
The Callback is never called, and i'm 100% sure the colision is working.
So, i create 1 sprite like this :
[src]
$spr[%i] = new t2dStaticSprite() { scenegraph = MySceneGraph; };
$spr[%i].setLayer( 13 );
$spr[%i].setCollisionMasks(BIT(2),BIT(13));
$spr[%i].setCollisionActive(true,true);
$spr[%i].setCollisionCallback( true );
// $spr[%i].setCollisionPhysics(false, false);
$spr[%i].setGraphGroup(1);
[/src]
The second sprite, pretty much the same thing :
[src]
$myimages[%x,%y] = new t2dStaticSprite() { scenegraph = MySceneGraph; };
$myimages[%x,%y].setLayer( 14 );
$myimages[%x,%y].setCollisionMasks(BIT(1),BIT(14));
$myimages[%x,%y].setCollisionActive(true,true);
$myimages[%x,%y].setCollisionCallback( true );
// $myimages[%x,%y].setCollisionPhysics(false, false);
$myimages[%x,%y].setGraphGroup(2);
[/src]
If i uncomment the setCollisionPhysics, i see them coliding as they start pushing eachother when moving
one agaisnt the other.
I really don't need physics here, i just need to know if they touch eachother, so i use the callback, like this :
[src]
function sceneWindow2D::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
echo("hereee");
}
[/src]
But nothing happens, no colision whatsoever.
Can anyone see what am i doing wrong here ?
thanks,
Bruno
About the author
#2
I created the Class , and defined a new onCollision for it, but it still doens't work. The Callback is not called.
Any other clues ?
10/23/2009 (12:16 am)
Thanks but.., it still doens't work.I created the Class , and defined a new onCollision for it, but it still doens't work. The Callback is not called.
Any other clues ?
#3
10/23/2009 (12:24 am)
care to post the whole code?... this way is much easier.
#4
Here it goes, i took non-relevant parts of the code.
btw, you know how the source tags work ?
[src]
$spr[%i] = new t2dStaticSprite() { scenegraph = MySceneGraph; };
$spr[%i].setLayer( 13 );
$spr[%i].setCollisionMasks(BIT(2),BIT(13));
$spr[%i].setCollisionActive(true,true);
$spr[%i].setCollisionCallback( true );
$spr[%i].setGraphGroup(1);
$spr[%i].Class = "teste";
$myimages[%x,%y] = new t2dStaticSprite() { scenegraph = MySceneGraph; };
$myimages[%x,%y].setLayer( 14 );
$myimages[%x,%y].setCollisionMasks(BIT(1),BIT(14));
$myimages[%x,%y].setCollisionActive(true,true);
$myimages[%x,%y].setCollisionCallback( true );
$myimages[%x,%y].setGraphGroup(2);
$myimages[%x,%y].Class = "teste";
function teste::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
echo("hereee");
}
[/src]
10/23/2009 (12:57 am)
sure thingHere it goes, i took non-relevant parts of the code.
btw, you know how the source tags work ?
[src]
$spr[%i] = new t2dStaticSprite() { scenegraph = MySceneGraph; };
$spr[%i].setLayer( 13 );
$spr[%i].setCollisionMasks(BIT(2),BIT(13));
$spr[%i].setCollisionActive(true,true);
$spr[%i].setCollisionCallback( true );
$spr[%i].setGraphGroup(1);
$spr[%i].Class = "teste";
$myimages[%x,%y] = new t2dStaticSprite() { scenegraph = MySceneGraph; };
$myimages[%x,%y].setLayer( 14 );
$myimages[%x,%y].setCollisionMasks(BIT(1),BIT(14));
$myimages[%x,%y].setCollisionActive(true,true);
$myimages[%x,%y].setCollisionCallback( true );
$myimages[%x,%y].setGraphGroup(2);
$myimages[%x,%y].Class = "teste";
function teste::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
echo("hereee");
}
[/src]
Torque Owner Ehrlich
say, your 2 sprites are of the Class "Truck", then, you should have the Truck::onCollision(...) function defined... and then it should work, but the way you have it right now, it wont.
PS: if you havent defined a class for your sprites, you can define it thru cod like this
and then create the onCollison callback.
good luck.