Get collision callback but not send or receive
by Phil Shenk · in Torque Game Builder · 07/05/2005 (2:45 am) · 11 replies
I'm sure I read some post on this, but I can't seem to find it.
Is it possible to get a collision callback, but not have any "physical" interaction between two sceneObjects?
To get no interaction, I have to turn off collisionActive send and receive, but then no callbacks happen.
I'm kind of tired though, so maybe I'm missing something. In case, it's not clear what I'm doing, I want to make "triggers" that a player can pass through, but will still get a collision callback.
Is it possible to get a collision callback, but not have any "physical" interaction between two sceneObjects?
To get no interaction, I have to turn off collisionActive send and receive, but then no callbacks happen.
I'm kind of tired though, so maybe I'm missing something. In case, it's not clear what I'm doing, I want to make "triggers" that a player can pass through, but will still get a collision callback.
About the author
#2
07/05/2005 (10:57 am)
It seems like "setCollisionPhysicsActive(false,false)" will deactivate the fxStaticSprite2D::onCollision() callbacks, as does "setPhysicsSuppress()"... I'm looking for a way to let an object pass through another, but generate the collisionCallback, so I can do stuff with it.
#3
The only thing that will turn off a collision callback is using "setCollisionActive()" or "setCollisionCallback()". Beyond those calls, callbacks always happen as do the responses.
You can see this logic in action in...
Cool?
- Melv.
EDIT: Just noted above that I typed it "setCollisionPhysicsActive()" rather than the correct "setCollisionPhysics()".
07/05/2005 (9:38 pm)
No, this isn't the case. "setCollisionActive()" turns the collision code on/off whereas "setCollisionPhysics()" turns the response (physics) on/off. "setPhysicsSuppress()" just overrides "setCollisionPhysics" so this also only turns the response off.The only thing that will turn off a collision callback is using "setCollisionActive()" or "setCollisionCallback()". Beyond those calls, callbacks always happen as do the responses.
You can see this logic in action in...
void fxSceneObject2D::processCollisionStatus( t2dPhysics::tCollisionStatus* pCollisionStatus, CDebugStats* pDebugStats )
Cool?
- Melv.
EDIT: Just noted above that I typed it "setCollisionPhysicsActive()" rather than the correct "setCollisionPhysics()".
#4
I just spent a few hours trying to get this figured out. Sorry to keep hammering this Melv. I'm suspecting that either something isn't working the way it should be, or I'm too dumb.
Anyway, right now, I've got this sample code that pastes right into a "fresh" client.cs . I've tried every possible combination of setCollisionActive(), but I can't get it to work.
The ONLY way I can get $o1 to pass through $o2 (and have the collision still be on, as shown by the debug collision boxes) is by setting:
(edit), changed the above code to "$o2.setCollisionPhysics( false, false);", which is how I was testing it.
07/05/2005 (11:26 pm)
Oy!I just spent a few hours trying to get this figured out. Sorry to keep hammering this Melv. I'm suspecting that either something isn't working the way it should be, or I'm too dumb.
Anyway, right now, I've got this sample code that pastes right into a "fresh" client.cs . I've tried every possible combination of setCollisionActive(), but I can't get it to work.
t2dSceneGraph.setDebugOn( BIT(5) );
// want to this one to pass through $o2, AND generate callback
// AND still be able to hit $o3
// ******************************************************************
$o1 = new fxStaticSprite2D("o1"){ sceneGraph = t2dSceneGraph; };
$o1.setImageMap( shipImageMap );
$o1.setPosition("-30 0");
$o1.setGroup( 1 );
$o1.setLayer( 1 );
$o1.setCollisionActive( true, true );
$o1.setCollisionMaterial( standardMaterial );
$o1.setCollisionMasks( BIT(1), BIT(1) );
$o1.setCollisionCallback( true );
$o1.setCollisionPhysics( true, true );
// want this to be "passable", but generate callback
// ******************************************************************
$o2 = new fxStaticSprite2D("o2"){ sceneGraph = t2dSceneGraph; };
$o2.setImageMap( shipImageMap );
$o2.setPosition("30 0");
$o2.setGroup( 1 );
$o2.setLayer( 1 );
// uncomment one of these
// $o2.setCollisionActive( true, true ); //blocks $o1, $o2 can't move
// $o2.setCollisionActive( false, true );//blocks $o1, $o2 can't move
// $o2.setCollisionActive( true, false );//blocks $o1, $o2 can't move
// $o2.setCollisionActive( false, false );//this has no collision
$o2.setCollisionMaterial( standardMaterial );
$o2.setCollisionMasks( BIT(1), BIT(1) );
$o2.setCollisionCallback( true );
$o2.setCollisionPhysics( false, false);
// immoveable
// ******************************************************************
$o3 = new fxStaticSprite2D("o3"){ sceneGraph = t2dSceneGraph; };
$o3.setImageMap( shipImageMap );
$o3.setPosition("0 20");
$o3.setGroup( 1 );
$o3.setLayer( 1 );
$o3.setCollisionActive( true, false );
$o3.setCollisionMaterial( standardMaterial );
$o3.setCollisionMasks( BIT(1), BIT(1) );
$o3.setCollisionCallback( true );
$o3.setCollisionPhysics( false, false );
$o3.setAutoRotation( 180 );
updateSprite();
}
function updateSprite()
{
$o1.setConstantForcePolar( angleBetween2D( $o1.getPosition(), sceneWindow2D.getMousePosition() ), 10000 );
schedule (33, 0, "updateSprite");
}
function fxStaticSprite2D::onCollision( %this )
{ echo("sprite: " @ %this.getname() @ " colliding"); }The ONLY way I can get $o1 to pass through $o2 (and have the collision still be on, as shown by the debug collision boxes) is by setting:
$o1.setCollisionActive( false, true ); .... $o2.setCollisionActive( false, true );But that generates no callbacks
(edit), changed the above code to "$o2.setCollisionPhysics( false, false);", which is how I was testing it.
#5
No problem, glad to help but we must be mis-communicating here or something. ;)
As I said above, use "setCollisionPhysics(false, false);" to stop any collision-response, NOT "setCollisionActive()" which turns-off the collision -detection! Your code above has this active so change the line to...
Yes?
- Melv.
07/06/2005 (12:40 am)
Phil,No problem, glad to help but we must be mis-communicating here or something. ;)
As I said above, use "setCollisionPhysics(false, false);" to stop any collision-response, NOT "setCollisionActive()" which turns-off the collision -detection! Your code above has this active so change the line to...
$o1.setCollisionPhysics( false, false );... and the thing collides without a physics response. I pasted this in a stock v1.0.2 and you get the callback with a collision response.
Yes?
- Melv.
#6
in this example:
> $o2 represents a "trigger" or "zone" that will generate a callback when the player ($o1) flys over it.
> $o3 represents all the other game objects like asteroids and enemies that the player needs to bounce off of.
Is there a way to do that?
I need a "zone" is another way of looking at it. Maybe there's another way altogether to get this thing.
... this "zone" I speak of.
-Phil
07/06/2005 (1:03 am)
Oh, I see... yeah that's not what I want. I mean it is, but I *also* want the "player" (represented in this case by $o1) to collide with other stuff. Like game objects that are "solid" (represented here by $o3). That's what I can't seem to find a way to do.in this example:
> $o2 represents a "trigger" or "zone" that will generate a callback when the player ($o1) flys over it.
> $o3 represents all the other game objects like asteroids and enemies that the player needs to bounce off of.
Is there a way to do that?
I need a "zone" is another way of looking at it. Maybe there's another way altogether to get this thing.
... this "zone" I speak of.
-Phil
#7
07/06/2005 (1:05 am)
This is good stuff :)
#8
If I understand you correctly then this mod to your original code will do the trick...
I've chosen to put the triggering into a different collision group but you could use a different layer if you want.
I changed the graphics a bit so I could see what was going on (they're all from the demo datablocks)!
Bri
(edit) I also changed %this.getname() to %this.getName() in the collision callback ;-)
07/06/2005 (4:02 am)
@Phil:If I understand you correctly then this mod to your original code will do the trick...
$o1.setCollisionCallback( true );
$o1.setCollisionPhysics( true, true );
// Create a "trigger" object
$m1 = new fxStaticSprite2D("m1"){ sceneGraph = t2dSceneGraph; };
// Doesn't need an image, uncomment next line to verify the "trigger" is in place
//$m1.setImageMap( ringImageMap );
$m1.setGroup( 2 );
$m1.setLayer( 1 );
$m1.setCollisionPhysics( false, false );
// Only receive collisions otherwise it will hit "o1" !
$m1.setCollisionActive( false, true );
// Uncomment this if you want the mount to also receive the collision callback
//$m1.setCollisionCallback( true );
// Ensure trigger goes where the player goes!
$m1.mount( $o1 );
// want this to be "passable", but generate callback
// ******************************************************************
$o2 = new fxStaticSprite2D("o2"){ sceneGraph = t2dSceneGraph; };
$o2.setImageMap( ringImageMap );
$o2.setCollisionPolyPrimitive( 16 ); // Just matching the image's shape for fun ;)
$o2.setPosition("30 0");
$o2.setGroup( 1 );
$o2.setLayer( 1 );
$o2.setCollisionPhysics( false, false);
// "Zone" will send collisions
$o2.setCollisionActive( true, false );
$o2.setCollisionMaterial( standardMaterial );
// The "zone" will only collide with objects in the "trigger" group
$o2.setCollisionMasks( BIT(2), BIT(1) );
$o2.setCollisionCallback( true );
// immoveable
// ******************************************************************I've chosen to put the triggering into a different collision group but you could use a different layer if you want.
I changed the graphics a bit so I could see what was going on (they're all from the demo datablocks)!
Bri
(edit) I also changed %this.getname() to %this.getName() in the collision callback ;-)
#9
Yeah that would be a way to do it. It's kind of cool, in that I could then have my "trigger" object set off different kinds of fields, depending on the groups. Shouldn't be too hard to set the customCollisionPoly to the same as the player either.
Good idea!
07/06/2005 (1:15 pm)
@BrianYeah that would be a way to do it. It's kind of cool, in that I could then have my "trigger" object set off different kinds of fields, depending on the groups. Shouldn't be too hard to set the customCollisionPoly to the same as the player either.
Good idea!
#10
I can see this functionality being useful, maybe it should be added to the suggestions list.
07/06/2005 (4:27 pm)
Yeah, it does what you want but.... I keep thinking that I'm missing something and that there's an easier way to do this...I can see this functionality being useful, maybe it should be added to the suggestions list.
#11
www.garagegames.com/mg/forums/result.thread.php?qt=32717
07/27/2005 (3:51 am)
Here's another thread on this problem (with what seems like the "easier" solution I was looking for)www.garagegames.com/mg/forums/result.thread.php?qt=32717
Associate Melv May
Hope this helps,
- Melv.