Game Development Community

Dts question

by Steve D · in Torque Game Engine · 04/01/2007 (7:12 pm) · 8 replies

After spending a lot time being frustrated I discovered that apparently the weapons in the modern weapons pack can't be collided with unless I'm missing something right in front of me! Is it possible to make dts shapes that don't have collison detection?

I typed in the torque logo code from the tutorial and it's collision works fine, no problems. When I substitute the dts file with a weapon dts from the above pack the collision doesn't work anymore.

So am I going crazy here or what?

#1
04/01/2007 (7:22 pm)
Idno much about the pack does it have mount point's on the weapon

I tried to find a refrence script for it, but do you have a collision function so when you collide it mounts that is all I can think of at this moment. I maybe wrong someone correct me if I'm wrong.


This is one from 3dallin1 for tommygun and item and car collision

function OrcClass::onCollision(%this,%obj,%col,%vec,%speed)
{
%obj_state = %obj.getState();
%col_className = %col.getClassName();
%col_dblock_className = %col.getDataBlock().className;
%colName = %col.getDataBlock().getName();

if ( %obj_state $= "Dead")
return;

if (%col_className $= "Item" || %col_className $= "Weapon" ) // Deal with all items
{
%obj.pickup(%col); // otherwise, pick the item up
}

%this = %col.getDataBlock();
if ( %this.className $= "Car" )
{
%node = 0; //find next available seat
%col.mountObject(%obj,%node);
%obj.mVehicle = %col;
}
}

I think I left some stuff out but it should get you started
#2
04/01/2007 (7:44 pm)
I can mount the weapons to the player just fine but I can't collide with them.
#3
04/01/2007 (7:57 pm)
Maybe you can put a collision box or mesh before your export it, or use sometype of zone (triggerZone and then doit function or something)

I'm still new to torque as well and haven't had time to learn that much about it but I did complete the 2 book's huge steep learning code for a none programmer like myself

just an idea
#4
04/01/2007 (8:10 pm)
Weapons can't have collision enabled by default, that's just the nature of the game.

That said, there are some things you can do, and should understand.

- A weapon consists of an image and an item.

- The image is what's mounted to the player's hands and what you see in first person view.

- The item typically concists of the actual weapon pickup, which exists in the world and can be used to equip the player with said weapon image upon the player colliding with the weapon item.

- The weapon image can not have collision.

- The weapon item can have collision. For this you'd have to set up a separate model with a collision box. This must only be used for the item and not the image.

- For a projectile to collide with an item you'd have to set up a "DamagableItemObjectType" item type:
datablock ItemData(yourWeaponItem)
{
   dynamicType  = $TypeMasks::DamagableItemObjectType;

   // Mission editor category
   category     = "Weapon";

   // Hook into Item Weapon class hierarchy. The weapon namespace
   // provides common weapon handling functions in addition to hooks
   // into the inventory system.
   className    = "Weapon";

   // Basic Item properties
   shapeFile    = "~/data/shapes/weapon/yourWeaponItem.dts";
   mass         = 2.0;
   elasticity   = 0.2;
   friction     = 0.6;
   emap         = true;
   maxInventory = 0;

   // Dynamic properties defined by the scripts
   explosion    = yourExplosion;
};

function yourWeaponItem::onCollision(%this, %obj, %col)
{
}

function yourWeaponItem::damage(%data, %obj, %position, %amount, %damageType)
{
}
#5
04/01/2007 (9:06 pm)
Hi Tim, ok my problem was that I was using staticshapedata instead of itemdata (stupid I know) but the thing is I can't place an itemdata object! It shows up in the proper category in world editor but when I click on it nothing happens. I double checked the path to the dts file so I know that is correct. This is so frustrating!
#6
04/01/2007 (9:15 pm)
Actually in the console it says it can't find itemdata::create - Is my installation folder damaged?
#7
04/01/2007 (9:27 pm)
If you're using the starter.fps kit there's a server side script named "item.cs" which handles all the support functions for items.

If you're using the tutorial base you'll need to add this script in yourself.

The most important function you'll need, the one which you are obviously missing and therefore can't spawn items in your world, is:
//-----------------------------------------------------------------------------
// Hook into the mission editor.

function ItemData::create(%data)
{
   // The mission editor invokes this method when it wants to create
   // an object of the given datablock type.  For the mission editor
   // we always create "static" re-spawnable rotating objects.
   %obj = new Item() {
      dataBlock = %data;
      static = true;
      rotate = true;
   };
   return %obj;
}
#8
04/02/2007 (6:38 am)
Just curious, why is this needed for an item shape but not a staticshape?