Game Development Community

breakable glass in game

by Shane Lunsford · in Torque Game Engine · 02/02/2012 (5:53 pm) · 3 replies

Hello i'm wondering if and how i would make breakable glass in torque3d. i found one thread from '02 and it had some ideals but didn't really boil down to an answer. Is there any one doing this or where should i start. Thank you

#1
02/02/2012 (5:56 pm)
Look for breakable or destroyable objects in the resources section.

In short, have a model that can detect damage (eg StaticShapeObject), hide/delete first model when damaged, swap to another model.
#2
02/02/2012 (6:13 pm)
Thank you I will read through it again then give it a shot.
#3
02/03/2012 (6:26 am)
Start here -- it works for all ShapeBase objects. I think I demonstrated how to substitute a broken shape as well as debris objects in the Resource/tutorial series, but just in case I didn't this is how you'd replace a healthy object with a busted one once it's onDestroyed() callback has been triggered:
function StaticShapeData::onDestroyed(%data, %obj, %prevState)
{
   //echo("\c4StaticShapeData::onDestroyed("@%data@", "@%obj@", "@%prevState@")");
    
   // If this is set to false then we delete the object when it is destroyed, 
   // we do so while it is still obscured by the explosion fx 	
   if (!%data.renderWhenDestroyed)
      %obj.schedule(200, "delete");  
    		
   %wreckage = new StaticShape() // You can change this for other object classes
   {
      datablock = NameOfBrokenObjectDatablockGoesHere; 
   };
   %wreckage.setTransform(%obj.getTransform());
   %wreckage.setScale(%obj.getScale());
   MissionCleanup.add(%wreckage);
}