Game Development Community

Confusing Collsion Responses

by Mike Lilligreen · in Torque Game Builder · 03/08/2006 (1:48 pm) · 10 replies

Not sure if this is a bug or simply a lack of understanding on my part.

If I have 2 objects on the screen with their setCollisionActive(true, true) and in the onCollsion callback I have:
function t2dSceneObject::onCollision(%srcObj, %dstObj)
{
   echo(%srcObj.getId() SPC %dstObj.getId());
}

In the console I get something like this:
1853 1851
1851 1853

This is fine, no problem here. But if I have one object with setCollisionActive(true, true) and one object with (true, false) or (false, true) I still get something like this:
1870 1853
1853 1870

Shouldn't in this last case the onCollsion be called only once between those 2 objects and not twice? At least that is the impression I get from reading what setCollsionActive does in the reference.pdf.
Quote:
NOTE:- Here you can specify bi-directionally, which collisions you're interested in. For
an object to collide with this object, it needs to specify that it can receive collisions.
Without this, the object will not be collided with.

#1
03/08/2006 (1:53 pm)
There is another thread going on especially with that content in.
It seems like this at the moment: If you set the physics for the collision, then the physic settings are taken into account as well for the collision callback.
I'm not sure if this is a desirable behavior as it somehow makes the setCollisionActive command useless if the physic one can overwrite it
#2
03/08/2006 (2:07 pm)
Well, in the second example I gave above, the object that has collsions set to (true, true) also had physics set to (true, true) but the one with collsions with (true, false) had physics (false, false). No physics stuff should have taken place, or am I wrong?

Update: ok, read the other thread as well. The problem doesn't just seem to be with the physics though, I turned physics off for all collision objects and having an object with setCollisionActive(true, false) or (false, true) acts exactly the same as if it was (true, true).
#3
03/08/2006 (2:15 pm)
Naw it shouldn't ...
this somehow is getting really confusing ... but thats where the beta is for (strangly this stuff didn't happen with alpha at least to me ...)
#4
03/08/2006 (2:24 pm)
Playing with this even more, 1 object setCollisionActive(false, true) and the other object (true, false), all physics off. Still get 2 onCollision() calls.
#5
03/09/2006 (6:37 am)
I noticed the same thing a while back and posted about it. Nobody ever answered me. Now I know I'm not crazy. What platform are you using?

-Peter
#6
03/09/2006 (6:51 am)
I get this as well.....really confused me!
#7
03/09/2006 (7:35 am)
I believe, that this is acting exactly as it should. With the setCollisionActive method you are specifying send and receive, so SetCollisionActive(false, true) would be saying to not send collisions, but do receive them, therefore you will get a callback with that object as the dest object. If the other object has SetCollisionActive(true, false), then you are going to receive a callback with that object as the src object. If you have an object that you want to receive collisions, but not produce a call back, the do setCollisionActive(false, true) AND setCollisionCallback(false).

As I understand it, that should produce the effect you are looking for.
#8
03/09/2006 (9:34 am)
I don't think it works like that.

If I have ALL objects set to only receive collisions, then onCollision will never be called because nothing sends a collision. Same if all objects are set to send collisions but not to receive them. This setup works fine in beta 1.1.

However, the problem comes when 1 object is set to send but not receive and the other is set to receive but not send. This should generate only 1 onCollision response, because only 1 of the objects can send a collision (and luckly the object being collided with can receive it). But instead T2D generates 2 onCollision calls, the second call being the object that can't send as %src and the object that can't receive as the %dst.

Honestly, this isn't a huge problem as I can setup my onCollision callback to handle the collision response properly, the engine is just calling onCollision() twice as much as it should.
#9
03/27/2006 (1:49 am)
I tried this again in beta 2. (Although I am guessing the only difference between beta 1.1 and 2 is the new level editor functionality?) Again, is it intended that both objects would be deleted with the way the collision response is set up? Or are we supposed to add dynamic fields to each object and sort collision responses that way?

Here is the example code:

//---------------------------------------------------------------------------------------------
// setupT2DScene
// This function is the starting point for all game specific code.
//---------------------------------------------------------------------------------------------
function setupT2DScene()
{
   // Create our scenegraph
   new t2dSceneGraph(t2dScene);

   // Associate Scenegraph with Window.
   sceneWindow2D.setSceneGraph(t2dScene);
   
   // Set the current camera position
   sceneWindow2D.setCurrentCameraPosition("0 0 800 600");
   
   // Load Test Collision Objects
   %test1 = new t2dStaticSprite(object1) {sceneGraph = t2dScene;};
   %test1.setImageMap(asteroidsImageMap);
   %test1.setSize("80 80");
   %test1.setPosition("100 0");
   %test1.setLayer(29);
   %test1.setGraphGroup(5);
   %test1.setCollisionActive(false, true);
   %test1.setCollisionPhysics(false, false);
   %test1.setCollisionDetection(CIRCLE);
   %test1.setCollisionCircleScale(0.8);
   %test1.setCollisionCallback(true);
   %test1.setCollisionGroups(5);
   %test1.setLinearVelocity("-30 0");
   
   %test2 = new t2dStaticSprite(object2) {sceneGraph = t2dScene;};
   %test2.setImageMap(asteroidsImageMap);
   %test2.setSize("80 80");
   %test2.setPosition("-100 0");
   %test2.setLayer(29);
   %test2.setGraphGroup(5);
   %test2.setCollisionActive(true, false);
   %test2.setCollisionPhysics(false, false);
   %test2.setCollisionDetection(CIRCLE);
   %test2.setCollisionCircleScale(0.8);
   %test2.setCollisionCallback(true);
   %test2.setCollisionGroups(5);
   %test2.setLinearVelocity("30 0");
}

// --------------------------------------------------------------------
// t2dSceneObject::onCollision(%srcObj, %dstObj)
// This function is triggered from the engine when a collision occurs
// --------------------------------------------------------------------
function t2dSceneObject::onCollision(%srcObj, %dstObj)
{
   echo(%srcObj SPC %dstObj);
   %srcObj.safeDelete();
}
#10
03/27/2006 (7:53 am)
Definitely sounds like a bug.