Game Development Community

onCollision command problems

by Jack-S- · in iTorque 2D · 10/06/2011 (6:14 am) · 4 replies

Hi, ive only just recently figured out the collision system but now I have another problem with onCollision...
in my scene I have a player which shoots a projectile and an enemy turret which also fires projectiles.
My onCollision command for the turret can capture the collision data such as %dstObj and %srcObj etc however my
projectile being fired from the player mysteriously cant. Im cloning this projectile using cloneWithBehaviors()
as clone() gave me errors.
So now im testing the turret for collisions of the players projectile I can get the data however for some reason my if states dont work and I have tried just about every variation of if statement I could find.
Basically im wanting to test that the %dstObj which is colliding with the enemy turret is the player projectile after that ive placed an echo but no results. I do notice though looking at the data that the %dstObj seems to increment itself with every collision. but still my if statements dont work.
Anyone got any ideas??
My data from collisions.

Turret Data
%dstObj =1194
%srcObj =1187
%dstRef =
%time =0.016788
%normal =-0.846565 0.532285
%contactCount =1
%contacts =154.242645 -102.592392

Turret Data
%dstObj =1195
%srcObj =1187
%dstRef =
%time =0.016788
%normal =-0.846565 0.532285
%contactCount =1
%contacts =154.242645 -102.592392

Turret Data
%dstObj =1196
%srcObj =1187
%dstRef =
%time =0.016788
%normal =-0.846565 0.532285
%contactCount =1

the function im using is.

function Turret::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)

some of the if statments I have tried are
if(%dstObj.isPlayerProjectile) which is the projectiles class

if(%dstObj.PlayerShipProjectile) which is the projectiles name

if(%dstObj $= "PlayerShipProjectile")

if(%dstObj.class $= "isPlayerProjectile")

after trying these I still cant compare %dstObj to the player projectile which collides with the turret which of course is the %srcObj the reciever...

the projectile code im using to fire the projectile is

if($shootActivated $= 1)
{
%projectileSpeed = 150;
%fireRate = 0.15;
%projectile = playerShipProjectile.cloneWithBehaviors(true);
%projectile.setPosition(playerShip.position);
%projectile.setRotation(playerShip.rotation);
%projectile.setLinearVelocityPolar(playerShip.rotation, %projectileSpeed);
schedule(%fireRate * 1000,0,"fire");
}
}

thanks and sorry for the long post.




#1
10/06/2011 (6:21 am)
Can you post the object code for the playerShipProjectile?
#2
10/06/2011 (6:44 am)
@Michael - Im not sure what else to post on the playerShipProjectile so ill post everything.
This is the function used to fire and clone the projectile.

function fire(%this, %touchID)
{
if($shootActivated $= 0)
{
cancel(schedule(%fireRate * 1000,0,"fire"));
}
if($shootActivated $= 1)
{
%projectileSpeed = 150;
%fireRate = 0.15;
%projectile = playerShipProjectile.cloneWithBehaviors(true);
%projectile.setPosition(playerShip.position);
%projectile.setRotation(playerShip.rotation);
%projectile.setLinearVelocityPolar(playerShip.rotation, %projectileSpeed);
schedule(%fireRate * 1000,0,"fire");
}
}

this is the playerShipProjectile datablock.

new t2dStaticSprite(playerShipProjectile) {
imageMap = "particles_glowImageMap";
frame = "0";
mUseSourceRect = "0";
sourceRect = "0 0 0 0";
canSaveDynamicFields = "1";
PlatformTarget = "UNIVERSAL";
class = "isPlayerProjectile";
Position = "2.000 -203.000";
size = "64.000 64.000";
Layer = "1";
GraphGroup = "1";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionGroups = "1";
CollisionLayers = "536870912";
CollisionCallback = "1";
CollisionMaxIterations = "3";
CollisionResponseMode = "KILL";
AlphaTestValue = "-1";
UsesPhysics = "1";
mountID = "12";
};
};

the name of the object is playerShipProjectile and its classname is isPlayerProjectile.
This is everything ive done concerning the playerShipProjectile.
#3
10/06/2011 (7:40 am)
@Jack-S- That's what I was looking for. I'll have a look in a bit.
#4
10/06/2011 (8:11 am)
@ michael hi I finally managed to get this using the command
getClassNamespace()

{
%colliderClass = %dstObj.getClassNamespace();
%srcClass = %srcObj.getClassNamespace();


echo(%colliderClass);
echo(%srcClass);

}

using this code it returned the class name of the %dstObj.

If its not too much bother could I possibly request a list of every single command available within torquescript? theres a number of commands that I have been using which arent in the reference and it would be incredibly usefull to have them.
thanks in advance.