Game Development Community

Collision problem

by Bristow · in Torque Game Engine · 04/22/2006 (12:21 pm) · 4 replies

Ok here is a piece of code I'm using:

function shotgunProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
%col.damage(%obj,%pos,%this.directDamage,"shotgunBullet");
radiusDamage(%obj,%pos,%this.damageRadius,%this.radiusDamage,"shotgunBullet",%this.areaImpulse);



if (%obj.getClassName() $= "Armor")
{
blood(%obj.position);
}
}


its part of a shotgun code for when the projectile collides with the target. with "blood(%obj.position)" it works fine except blood comes out when you shoot anything. I have an if statement there but then blood just never comes out (I tried using "player", that didn't work either) I just want to know how I would set up an if statement on a collision that would make the blood only get activated when the projectile hits an object with a certain name or classname,how would I do that?

#1
04/22/2006 (2:31 pm)
Have you tried echoing %obj.getClassName() to see what it's actually returning?
#2
04/22/2006 (10:21 pm)
Doh!
Didn't think to try that
#3
01/19/2010 (1:43 am)
I know this thread is a bit old, but your problem is that %obj is the person who shot the shotgun, %col is what the projectile collides with.

Try this:

if (%col.getClassName() $= "Armor")
{
blood(%col.position);
}
}
#4
01/19/2010 (1:47 am)
Jonathan - you're right ;). But also, %col is the object, and its class will be Player.
if(%col.getClassname() $= "Player")
or
if(%col.getDataBlock().className $= "Armor")

EDIT: But the best place to put blood effects would be in Armor::onDamage. Think about it - it's your Players that are full of blood, not the Projectiles!