Game Development Community

How to select a random shapeFile for a debris datablock?

by Sam Edge · in Torque Game Engine · 06/08/2009 (6:45 am) · 2 replies

I have some destructible jars and they break into 3-4 pieces when broken. Debris shoot from the explosion. Rather than creating 4 different debris data blocks I thought it would be more efficient to adjust the shapeFile field in the datablock before the object is created. I thought I could do this by overridding the create function of the DebrisData object:

function JarDebris::create( %data )
{
    %chosen = getRandom( 0, 3 );
    echo( "Chose Number: ", %chosen );
    
    switch( %chosen )
    {
    case 0:
        %data.shapeFile = "art/shapes/collada/objects/jars/jar_a.dae";
    case 1:
        %data.shapeFile = "art/shapes/collada/objects/jars/jar_b.dae";
    case 2:
        %data.shapeFile = "art/shapes/collada/objects/jars/jar_c.dae";
    case 3:
        %data.shapeFile = "art/shapes/collada/objects/jars/jar_d.dae";
    }

   %obj = new DebrisData() {
      dataBlock = %data;
   };

   return %obj;    
}

The function doesn't appear to work. Any suggestions? Many thanks :)

#1
06/08/2009 (11:11 am)
> Rather than creating 4 different debris data blocks I thought it would be more efficient to adjust the shapeFile field in the datablock before the object is created.

hey Sam - good thinking, but in this case it'll lead you down a dead-end. Datablocks are defined as being unchangable once they're created, so you'll need to create several different datablocks and randomly choose between them. there's lots of discussion on why DB's are write-once in the forums and site, if you want to delve deeper.
#2
06/08/2009 (11:23 am)
Cool thanks for the info!