How to delete/destroy an object upon collision?
by Katie · in Technical Issues · 08/23/2009 (11:33 am) · 4 replies
Perhaps I am just a n00b but I have spent way too much time trying to find a simple article or website that explains the delete or destroy function.
I want a certain type of object in my game to be deleted when a player collides with it. I know that something has to go within this function:
function SuperBomb::onCollision( %this, %obj, %col )
{
echo( "SuperBomb::onCollision called ----------------------------------" );
}
I just don't know what. I have "3D Game Programming All In One" by Ken Finney. Before just giving me the answer, could someone direct me to somewhere either in this book or a website that can tell me how to do this? I want to learn, but at the same time, my final exam is next week and this project is due Tuesday. I just need some direction! Thank you!
I want a certain type of object in my game to be deleted when a player collides with it. I know that something has to go within this function:
function SuperBomb::onCollision( %this, %obj, %col )
{
echo( "SuperBomb::onCollision called ----------------------------------" );
}
I just don't know what. I have "3D Game Programming All In One" by Ken Finney. Before just giving me the answer, could someone direct me to somewhere either in this book or a website that can tell me how to do this? I want to learn, but at the same time, my final exam is next week and this project is due Tuesday. I just need some direction! Thank you!
About the author
I'm attending the DeVry University in Crystal City, VA for a Bachelor's in Game and Simulation Programming. I've always loved video games and hope to be a part of making them someday. My dream is to see my name in the credits of a popular game.
#2
Thats the only thing I can think of. I looked at how the crossbow does it, but it's a ballistic so it appears to self delete in the C code.
08/23/2009 (2:28 pm)
%obj.delete();Thats the only thing I can think of. I looked at how the crossbow does it, but it's a ballistic so it appears to self delete in the C code.
#3
08/23/2009 (2:36 pm)
That's it! ^_^ I added that into the onCollision function and it worked. A tip for anyone else who tries this -- make sure you don't place a static shape of the object, or your player will just walk into it. :P Thanks again, Mike!
Katie
http://www.codesampler.com/torque.htm
//-----------------------------------------------------------------------------
// 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";
};
//-----------------------------------------------------------------------------
// 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 )
{
echo( "SuperBomb::onCollision called ----------------------------------" );
// TO DO: Add code here to have the player react to touching the power-up!
}
=============================
Can someone tell me how to delete this object upon collision?