Trying to make a Landmine (failing)
by Daniel DiCicco · in Torque Game Engine · 04/28/2004 (1:00 pm) · 2 replies
Hello.
I've just begun messing around with Torque and have gone through a number of tutorials. Using the samples from codesample.com/torque, I created a "superbomb.cs" item with the following code:
I am trying to turn this object into an explosive. When the oncollision is called, I'd like damage to be done and an explosion to occur. Right now, all that I can do is make the object hurt the player. Thus far, any attempts to produce an explosion or impulse effect have failed. Can someone point me in the right direction here?
Thanks,
Dan
I've just begun messing around with Torque and have gone through a number of tutorials. Using the samples from codesample.com/torque, I created a "superbomb.cs" item with the following code:
//-----------------------------------------------------------------------------
// Datablocks are special objects that are used to transmit static data from
// server to client. Datablocks are declared as followed:
//
// datablock datablock_class (datablock_name)
// {
// field1 = value;
// };
//
// Here's the datablock for our new Super Bomb power-up...
//
//-----------------------------------------------------------------------------
datablock ItemData( SuperBomb )
{
// The mission editor uses the "category" variable to organize this new
// item under the "shapes" root category.
category = "Bombs";
// Next, we'll tell the mission editor where to find the .dts shape file
// that defines our Super Bomb's geometry.
shapeFile = "~/data/shapes/superbomb/superbomb.dts";
radiusDamage = 10;
areaImpulse = 500;
};
//-----------------------------------------------------------------------------
// The mission editor will invoke this create() method when it wants to create
// an object of our new datablock type. This is a good time to setup any
// default behavior for our object. For example, our new object's default
// behavior is to be unmovable or static and rotate in place.
//-----------------------------------------------------------------------------
function ItemData::create( %data )
{
echo( "ItemData::create for SuperBomb called --------------------------" );
%obj = new Item()
{
dataBlock = %data;
rotate = true; // All Super Bomb power-ups will rotate.
static = true; // Super Bombs should stay put so they don't slide away.
};
return %obj;
}
//-----------------------------------------------------------------------------
// And, of course, what good is a Super Bomb power-up if we can't tell when
// the player is touching it? Every time our player touches a Super Bomb the
// onCollision() function below will get called.
//-----------------------------------------------------------------------------
function SuperBomb::onCollision( %this, %obj, %col )
{
// my failing attempt to get an explosion working
explosion = RocketExplosion;
if( %col.getType() & $TypeMasks::ShapeBaseObjectType )
{
%col.damage( %obj, %pos, 50, "Mine" );
radiusDamage( %obj, VectorAdd(%pos, VectorScale(%normal, 0.01)),
4.0 , %this.radiusDamage, "MineRadius", %this.areaImpulse );
}
// TO DO: Add code here to have the player react to touching the power-up!
}I am trying to turn this object into an explosive. When the oncollision is called, I'd like damage to be done and an explosion to occur. Right now, all that I can do is make the object hurt the player. Thus far, any attempts to produce an explosion or impulse effect have failed. Can someone point me in the right direction here?
Thanks,
Dan
#2
That *should* work.
04/28/2004 (4:43 pm)
Use this:function SuperBomb::onCollision( %this, %obj, %col ){
if( %col.getType() & $TypeMasks::ShapeBaseObjectType ) {
%col.damage( %obj, %obj.getPosition(), 50, "Mine" );
%obj.setDamageState(Destroyed);
%obj.schedule(200, "delete");
}
}
function SuperBomb::onDestroyed(%data, %obj, %pos, %mod)
{
%pos = %obj.getPosition();
radiusDamage( %obj, %pos, 4.0 ,%data.radiusDamage, "MineRadius", %data.areaImpulse );
}That *should* work.
Torque Owner Dan -