Game Development Community

Collision detection problem [solved]

by Jonas Dahlman · in Torque Game Builder · 04/08/2010 (1:08 pm) · 1 replies

Hello

I am having some issues with some collision things in my scripts.

Basically I want to print to the console if a line hits an obstacle.
Everything needs to be created via scripts and not the editor.

I have checked for examples here on the forums and also the example tutorials and such however I haven't found what's wrong in my script as the script below doesn't print anything with the collision :(

function line::createLine(%this, %position)
{
%this = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
class = line;
size = "100 5";
position = %position;
};

%this.setImageMap("line");
%this.setCollisionDetection(POLYGON);
%this.setCollisionActive( true, true );
%this.setCollisionPhysics(false, false);
%this.setCollisionCallback(true);
}

function obstacle::onLevelLoaded(%this)
{
%this.setCollisionDetection(POLYGON);
%this.setCollisionActive( true, true );
%this.setCollisionPhysics(false, false);
%this.setCollisionCallback(true);
}

function obstacle::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
if(%dstObj.class $= "line")
{
echo("Collision hit!");
}
}

Thanks for the help!

#1
04/09/2010 (7:47 am)
Ignore this as I have found the problem.. The script was wrong and also I had messed up the datablocks accidentally :/