Sword not colliding with static shapes
by Dylan West · in Technical Issues · 08/11/2008 (4:51 am) · 2 replies
I have a question about sword collisions, I'm hoping someone can help me with:
How do I set up a sword to collide with barrels, boulders and other objects? I have set up the melee resource from Josh Moore
(http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5377)
and got that to successfully kill bots. I have also set up the exploding barrels from Ken Finney's Advanced 3D Game Programming All in One book and they explode just fine when struck with a crossbow bolt. Now, when I strike it with a sword, it doesn't explode, though my sword can kill bots. I suspect it doesn't work with the barrels because I have no SwordProjectile::onCollision method set up in sword.cs. So I tried to set that up using CrossbowProjectile::onCollision as an example and still saw no collisions or explosions. I really want to figure this out because I want to be able to get the sword to do more than just kill bots. I want to cut tall grass, knock rigidshapes around, like my rollable boulders, etc...
Does anyone have any ideas?
How do I set up a sword to collide with barrels, boulders and other objects? I have set up the melee resource from Josh Moore
(http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5377)
and got that to successfully kill bots. I have also set up the exploding barrels from Ken Finney's Advanced 3D Game Programming All in One book and they explode just fine when struck with a crossbow bolt. Now, when I strike it with a sword, it doesn't explode, though my sword can kill bots. I suspect it doesn't work with the barrels because I have no SwordProjectile::onCollision method set up in sword.cs. So I tried to set that up using CrossbowProjectile::onCollision as an example and still saw no collisions or explosions. I really want to figure this out because I want to be able to get the sword to do more than just kill bots. I want to cut tall grass, knock rigidshapes around, like my rollable boulders, etc...
Does anyone have any ideas?
#2
08/11/2008 (11:19 am)
Well the way it works for dealing damage to players, you should NOT call applyDamage directly. You need to call the Player::Damage or PlayerData::Damage methods. It looks like the BarrelA::Damage is what determines when its time for the barrel to explode. So you call applyDamage, it might be at -200 health but it will not explode...
Torque Owner Dylan West
%object.applyDamage(%damage);
where %object is the handle of the barrel. I have used echo statements to confirm this is detecting the barrel properly.
Now here is the code that would destroy the barrel if I shot it with a crossbow:
function BarrelA::Damage(%theDatablock,%aBarrel,%sourceObject,%pos,%damage,%damagetype)
{
%aBarrel.applyDamage(%damage);
echo("damage to barrel detected");
if(%aBarrel.getDamageLevel() >= %theDatablock.maxDamage)
%theDatablock.Explode( %aBarrel ,%pos);
echo("called barrelA::Damage");
}
function BarrelA::Explode(%theDatablock, %aBarrel, %position)
{
echo("called barrelA::Explode");
echo("theDatablock is " @ %theDatablock @ "aBarrel is " @ %aBarrel @ "position is " @ %position);
if(%aBarrel.exploded)
return;
%aBarrel.exploded = true;
%boom = new Explosion()
{
datablock = FuelExplosion;
position = %position;
sourceObject = %aBarrel.sourceObject;
sourceSlot = %aBarrel.sourceSlot;
client = %aBarrel.client;
};
MissionCleanup.add(%boom);
radiusDamage(%aBarrel,%position,%theDatablock.damageRadius,
%theDatablock.radiusDamage,%source.damageType,%theDatablock.damageImpulse);
%aBarrel.schedule(500, "delete");
}
I understand that the applyDamage() method and the BarrelA::Damage() method are different methods, but wouldn't the two be connected? If I'm causing damage with the %object.applyDamage() method to the barrel, wouldn't that be good enough? And I still don't understand why the OnCollision callback works with the crossbow, but whenever I try to set that up for the sword, it fails.