Game Development Community

Collision response

by Jason McIntosh · in Torque Game Builder · 02/28/2005 (7:17 am) · 5 replies

I may be having another "doh!" moment here, but my objects don't respond when they collide. The callback function is getting called, because it spews object ids to the console just like I tell it to. :) Is there something else to turn on to get collision responses from the physics system?

I assume leaving off the collisionPolyCustom() will default to the quad, which is what it looks like is happening, so I don't think that's the problem.

//
	// Test ball
	//
	datablock fxImageMapDataBlock2D( ballImageMap )
	{
		mode = cell;
		cellWidth = 24;
		cellHeight = 24;
		cellCountX = 8;
		cellCountY = 5;
		textureName = "~/client/resource/balls/Pillbug/images/pillbug";
	};
	$ball = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
	$ball.setPosition( "0 0" );
	$ball.setSize( "3 3" );
	$ball.setImageMap( ballImageMap );
	$ball.setFrame( 19 );

	$ball.setLayer( $LAYER_PLAYFIELD );
	$ball.setGroup( $COLLISION_GROUP_BALL );
	$ball.setCollisionPolyPrimitive( 16 );
	$ball.setCollisionActive( true, true );
	$ball.setCollisionMaterial( projectileMaterial );
	$ball.setCollisionMasks( BIT($COLLISION_GROUP_PLAYER) | BIT($COLLISION_GROUP_BRICK) | BIT($COLLISION_GROUP_TOTEM), BIT($LAYER_PLAYFIELD) );
	$ball.setCollisionCallback( true );

	$ball.setWorldLimit( bounce, "-50 -35 50 35" );
	$ball.setLinearVelocityY( -40 + ( getRandom() * 80 ) );
	$ball.setLinearVelocityX( -40 + ( getRandom() * 80 ) );
// Player 1 setup.
		$player1.setPosition( "-35 0" );
		$player1.setImageMap( jackImageMap );
		$player1.setSize( "8 8" );
		$player1.setWorldLimit( clamp, "-50 -35 50 35" );
		
		$player1.setGroup( $COLLISION_GROUP_PLAYER );
		$player1.setLayer( $LAYER_PLAYFIELD );
		$player1.setCollisionActive( true, true );
		$player1.setCollisionMaterial( standardMaterial );
		$player1.setCollisionMasks( BIT($COLLISION_GROUP_BALL), BIT($LAYER_PLAYFIELD) );
function fxSceneObject2D::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
	echo( "COLLISION: " @ %srcObj @ " hit by " @ %dstObj );
}

#1
02/28/2005 (7:54 am)
Edited ---- incorrect data-- sorry for the confusion



If you are getting ids then if IS colliding so now you do stuff to the objects now that you have them.
#2
02/28/2005 (8:04 am)
Anthony,
which should be
$player1.setGroup( bit($COLLISION_GROUP_PLAYER) );
$player1.setLayer( bit($LAYER_PLAYFIELD ));
didn't seem to change anything, except the layers are in a weird order. I didn't think those were bitfield parameters? I thought only the collisionMasks were bitfields? (I got invalid layer errors in the console, in fact.)

The values are:
$COLLISION_GROUP_PLAYER =	1;
$COLLISION_GROUP_BALL = 	2;
$COLLISION_GROUP_BRICK = 	3;
$COLLISION_GROUP_TOTEM =	4;

$LAYER_BOTTOM = 			31;
$LAYER_BACKDROP = 			25;
$LAYER_PLAYFIELD = 			15;
$LAYER_HUD = 				5;
$LAYER_TOP =				0;
#3
02/28/2005 (8:34 am)
Add this to your ball creation:

%ball.setCollisionPhysics( true, true );
#4
02/28/2005 (9:12 am)
Strike what I said, sorry for the confusion
#5
02/28/2005 (10:01 am)
Harold, rock out! That's what I was missing. Thanks man!