Game Development Community

Collision Poly Help

by Brian A. · in Torque Game Builder · 03/08/2005 (7:13 pm) · 6 replies

I have been working setting up collision system for a game. I noticed that as soon as I define a group/layer my players image map disappears. Does this happen if you do not have the right vertices in place with the setCollisionPolyCustom line?

// Set player's collision info:
$playerShip.setGroup( 1 );
$playerShip.setLayer( 1 );
$playerShip.setCollisionActive( true, true );
$playerShip.setCollisionMaterial( standardMaterial );
$playerShip.setCollisionPolyCustom( 4, "-1 0 -0.1 -0.6 0.98 0.15 -0.1 0.7" );
$playerShip.setCollisionMasks( BIT(2), BIT(2) );
$playerShip.setCollisionCallback( true );

I read in the Technical Overview that there are defaults. Does the system automatically set collisionPoly if you do not create custom edge/verts line?

#1
03/09/2005 (4:10 am)
Brian,

Everything here is fine, including the custom-polygon. To quickly answer your question first, no, the collision polygon has nothing to do with rendering at all. To answer your other question, yes, the system defines a quad collision-polygon by default that matches the objects bounding-box and therefore the texture.

There's not really enough info here for me to see exactly what might be happening but there maybe some trivial things to check.

You say that your object disappears when you set the group/layer. If you are changing to layer#1 (as above) then the only reason I can think is that you have something on layer#0 obscuring the player? Maybe some background sprite?

If it happens when you set the group, it could be because your player is colliding with some large object in the scene and is solving the overlap situation which causes the object to move away from the object and therefore possibly off the screen.

It might be worth you either posting the relevant code (just the impotant parts) here or perhaps try activating the debug-info panel "mySceneGraph.setDebugOn(BIT(0));" and check for how many objects there are in the scene, how many potential renders and how many actual renders.

Hope this helps,

- Melv.
#2
03/09/2005 (6:39 pm)
Here is the code for the enemy section. If I delete the "// Set enemy collision info" my enemy graphic show up with no problem. I do have a sprite called nebula - its a sprite graphic that I use to scroll as a background, but I did not assign any collision info on it (see code below) Any ideas?


// ---------------------------------------------------------------------
// Enemy Section
// ---------------------------------------------------------------------

function CreateEnemy()
{
// Create an enemy ship
%enemySpider = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
%enemySpider.setSize ("7 7");
%enemySpider.setPosition((-40 + (getRandom() * 60) SPC "-30"));
%enemySpider.setImageMap (enemySpiderImageMap);
//attachThruster( %enemySpider, "0.8 -0.12", 180 );
//attachThruster( %enemySpider, "0.8 0.18", 180 );

// Set enemy collision info
%enemySpider.setGroup( 2 );
%enemySpider.setLayer( 2 );
%enemySpider.setCollisionActive( true, true );
%enemySpider.setCollisionMaterial( standardMaterial );
%enemySpider.setCollisionPolyCustom( 5, "-0.9 0 0 -0.6 1 -0.3 1 0.3 0 0.5" );
%enemySpider.setCollisionMasks( BIT(1), BIT(1) );
%enemySpider.setCollisionCallback( true );

//move the enemy towards us
%enemySpider.setLinearVelocityY(13);
%enemySpider.setWorldLimit( kill, "-60 -40 60 40" );

// Create and enemy missle and fire it
%enemyFire = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
%enemyFire.setPosition( %enemySpider.getPosition() );
%enemyFire.setSize( ".4 2.8" );
%enemyFire.setImageMap( playerMissileImageMap );
%enemyFire.setLinearVelocityY( 35 );
%enemyFire.setWorldLimit( kill, "-60 -40 60 40" );

// Set up collision info
%enemyFire.setGroup( 2 );
%enemyFire.setLayer( 2 );
%enemyFire.setCollisionActive( true, true );
%enemyFire.setCollisionMaterial( standardMaterial );
%enemyFire.setCollisionScale("0.9 0.5");
%enemyFire.setCollisionMasks( BIT(1), BIT(1) );
%enemyFire.setCollisionCallback( true );

schedule(2000, 0, "CreateEnemy");
}
	
function KillPlayer()
{
$playerShip.setVisible( false );
playerMap.pop();
schedule(2000, 0, "ResetPlayer");
}

function ResetPlayer()
{
$playerShip.setPosition("-35 0");
$playerShip.setVisible(true);
playerMap.push();
}

function fxSceneObject2D::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
if (%srcObj == $playerShip)
{
KillPlayer();
%dstObj.safeDelete();
}
else if (%dstObj == $playerShip)
{
KillPlayer();
%srcObj.safeDelete();
}
else
{
%srcObj.safeDelete();
%dstObj.safeDelete();
}
}
// ---------------------------------------------------------------------
// Star Background Section
// ---------------------------------------------------------------------
function SetupStarScroller()
{
// Create image for star Map
datablock fxImageMapDatablock2D(StarScrollImageMap)
 {    
 mode = full;   
 textureName = "~/client/images/StarsBlack"; };
  
datablock fxImageMapDatablock2D(StarScrollImageMapA)
 {    
 mode = full;   
 textureName = "~/client/images/StarsA"; };  

datablock fxImageMapDatablock2D(StarScrollImageMapB)
 {    
 mode = full;   
 textureName = "~/client/images/StarsB"; }; 
 }
#3
03/09/2005 (6:40 pm)
And the starMap

function CreateStarMap()
{
// Create Main        
%StarScroll = new fxScroller2D() { scenegraph = t2dSceneGraph; };
%StarScroll.setImageMap( StarScrollImageMap );
%StarScroll.setSize("100 200");
%StarScroll.setRepeat ("1 1");
%StarScroll.setScroll( "0 -4" );

// Stars A
%StarScrollA = new fxScroller2D() { scenegraph = t2dSceneGraph; };
%StarScrollA.setImageMap( StarScrollImageMapA );
%StarScrollA.setSize("100 200");
%StarScrollA.setRepeat ("1 1");
%StarScrollA.setScroll( "0 -8" );

// Stars B
%StarScrollA = new fxScroller2D() { scenegraph = t2dSceneGraph; };
%StarScrollA.setImageMap( StarScrollImageMapB );
%StarScrollA.setSize("100 200");
%StarScrollA.setRepeat ("1 1");
%StarScrollA.setScroll( "0 -5" );
}
function CreateNebula()
{
// Create an image for the Nebula	
	datablock fxImageMapDatablock2D(nebulaImageMap)
	{
	mode = full;
	textureName = "~/client/images/nebula"; 
	};
// Nebula activate
%NebualScrollA = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
%NebualScrollA.setImageMap(nebulaImageMap);
%NebualScrollA.setSize("100 100");
//%NebualScrollA.setSize((20+(getRandom() * 100) SPC (getRandom() * 100)));
%NebualScrollA.setPosition((-70 + (getRandom() * 70) SPC "-75"));
%NebualScrollA.setLinearVelocityY( 4 );
//%NebualScrollA.setWorldLimit( kill, "-60 -40 60 40" );
schedule(25000, 0, "CreateNebula");
}
#4
03/10/2005 (12:59 am)
Brian,

Now I'm totaly confused. You started by saying that your player doesn't show and now in your second post you're talking about your enemy not showing. The code you've posted doesn't show the player being created either. Is it identical to the first post? What about the position?

It's pretty hard for me to understand what might be going on without knowing exactly what I'm looking for or seeing all the relevant code.

I'd definately recommend using the debug-info panel "t2dSceneGraph.setDebugOn(BIT(0));" to look at how many objects are in the scene as well as how many are rendering.

In your collision callback. If there's any collision that doesn't involve a $player object, both source and destination objects are deleted, is this what you want?

Probably easier if you post me the files or edit the ones above so that I can see if I can help.

- Melv.
#5
03/11/2005 (5:30 pm)
Melv,

I sent you the files... let me know if you did not get them. Thanks again for the help!
#6
03/12/2005 (2:45 am)
@Brian: I got them, sorry I've not got back yet. I've got a couple of peoples files to check but I've just been so busy with work and other T2D stuff, sorry.

I will get around to looking at these files, sorry it's taking so long.

- Melv.