Game Development Community

new object help

by Minesh · in Torque Game Engine · 08/13/2009 (4:17 pm) · 8 replies

Well i was wondering if i can make new object like a oilbarrel what would the datablock or %obj thing have to be?

#1
08/15/2009 (1:41 pm)
Unless you wanted to be able to interact/use/destroy the barrel you wouldn't need be concerned about datablocks or %obj --
  • put your dts and texture(s) somwhere in the shapes directory.
  • place the object in your mission through the Static Shapes list in the Creator Tree in the editor.

  • #2
    08/17/2009 (2:29 pm)
    Well i just want it to be destoryed if its hit by something
    #3
    08/17/2009 (3:00 pm)
    If you want to delete it you can use...

    Object.Delete();

    But, Any object with a datablock can have an onCollision function, which is automatically called when the object collides with another object.The engine provides you with three pieces of data when this happens...
    %this: the datablock,
    %obj: the individual object,
    %col: the object that was collided with.

    function oilbarrel::onCollision(%this, %obj, %col)
    {
    if(%col.getClassName() $= "Player");
    %obj.delete();
    }
    #4
    08/17/2009 (3:28 pm)
    All shapebase objects already have the capability of being destroyed built in. You can even have animated sequences or even swap different meshes in order to represent the object taking damage being deformed and eventually destroyed.

    In the datablock for your object make sure it has these fields
  • maxDamage
  • disabledLevel
  • destroyedLevel
  • Set these to values you want. disabledLevel should be less than destroyed level, and destroyedLevel should not exceed maxDamage.

    You'll then need a damage method for your object.
    function StaticShapeData::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
    {
       echo("\c4StaticShapeData::damage("@%data.getName()@", "@%obj@", "@sourceObject@", "@%position@", "@%amount@", "@%damageType@")");
       %obj.applyDamage(%damage);
    }
    
    function StaticShapeData::onDamage(%data, %obj)
    {
       echo("\c4StaticShapeData::onDamage("@%data@", "@%obj@")");
    
       // Set damage state based on current damage level, we are comparing amount
       // of damage sustained to the damage levels described in the datablock and
       // setting the approppriate damageState
       %damage = %obj.getDamageLevel();
       if (%damage >= %data.destroyedLevel)
       {
          if (%obj.getDamageState() !$= "Destroyed")
          {
             %obj.setDamageState(Destroyed);
             %obj.setDamageLevel(%data.maxDamage);
          }
       }
       else if(%damage >= %data.disabledLevel)
       {
          // you could call an animation sequence here to represent the deformation
          // of the object by damage.  You can have as many sequences as you want,
          // so long as you set up your damage amount to damage level comparisons
          if (%obj.getDamageState() !$= "Disabled")
             %obj.setDamageState(Disabled);
       }
       else
       {
          // we're just assuming that the object is still nice and healthy -- until
          // it is hurt some more that is.
          if (%obj.getDamageState() !$= "Enabled")
             %obj.setDamageState(Enabled);
       }
    }
    #5
    08/17/2009 (3:43 pm)
    I use StaticShapeData namespace so as to not have to contantly duplicate code for different objects. Almost all destroyable props would be StaticShapes anyway, but the above method will work for rigidshapes and vehicles too. Note: the StaticShape class is different from the Static Shapes object list in the editor which is populated with TSStatics. Many people get hung up in confusion there. "True" StaticShapes will require a datablock.
    #6
    08/17/2009 (5:13 pm)
    Well i have some trouble trying tomake the Object as a static itsself
    #7
    08/17/2009 (5:14 pm)
    datablock StaticShapedata(FuelKeg)
    {
    shapefile = "~/data/shapes/Keg.dts";
    category = "Item";
    classname = "Item";
    maxdamage = 100;
    image = FuelKeg;
    };
    #8
    08/17/2009 (5:16 pm)
    And i tried to Find out how to make the SHape transform but it dont work for some reason