Game Development Community

Porting hitboxes

by Aleksander Elvemo · in Torque 3D Professional · 08/27/2009 (2:32 pm) · 38 replies

Hi there!

Im doing some work on hitboxes, as it is a critical feature for our game. I've been looking at the resource:
http://www.garagegames.com/community/resources/view/6538
and thought it would be a great starting point, as its already ported to tgea 1.8.1.
I got some compile errors however, in the TSShapeInstance::castRayEA function.
The following lines caused errors;

setStatics(dl); -> 'setStatics': identifier not found
clearStatics(); -> 'clearStatics': identifier not found
MeshObjectInstance* *mesh = &mMeshObjects[HBIndex]; -> cannot convert from 'TSShapeInstance::MeshObjectInstance *' to 'TSShapeInstance::MeshObjectInstance **'

I tried to just comment them out, but i believe that won't help me in the long run ;)

Anyone got an idea? Im sure many others want hitboxes in their T3D game! =)
Page «Previous 1 2
#1
08/27/2009 (3:05 pm)
The setStatics/clearStatics stuff has been replaced by the TSRenderState class, which allows for a much cleaner way to pass data down to the TSShapeInstance render instance submission functions. What parameter was the hitbox code trying to set (detail level?)? You may or may not actually need to use TSRenderState.

As for the other error, this
MeshObjectInstance* *mesh = &mMeshObjects[HBIndex];
Is due to the fact that you have two dereference operators there for your "mesh" variable, so it thinks you're trying to assign to a pointer-pointer. Instead you want
MeshObjectInstance *mesh = &mMeshObjects[HBIndex];
#2
08/27/2009 (3:20 pm)
Yes, it tried to assign the detail level,
setStatics(dl);

so its not needed?

also, this removed the error with MeshObjectInstance! :D
MeshObjectInstance *mesh = &mMeshObjects[HBIndex];

Thanks a million, lightning quick answer also :)
#3
08/27/2009 (3:34 pm)
Uh well if the resource was setting the detail level to something very specific, you might want to preserve that. I would just test it without first and see how it goes. If you have problems you should be able to pass the detail level to your TSShapeInstance::render() function (whereever the set/clearStatics methods were being called).
#4
08/28/2009 (11:09 am)
Hmm, i don't know if its the commented out code (set & clearStatics) or if i export the model out wrong, i can't seem to get the hitboxes working.

Using blender to export the model, and when opening it up in showtool it shows the hitboxes as seperate Objects named HB1 -> HB11 (11 different hitboxes). So i guess the exporter doesn't include the "_detailnumber" after the hitboxnumber.

Can anyone enlighten me on how to name the objects in blender and get the hitboxes in? I'm sure this is a valuable resource to get in T3D!
#5
08/29/2009 (3:28 pm)
Ok, i have hitboxes in the game, they are being picked up in the ShapeBaseData::preload function and assigned to HBIndex!

So, when i shoot our unlucky bot the game crashes marveously! So, the hitboxes are detected by the projectile fired.

The final question is as follows, has the commented code "setStatics(dl)" and "clearStatics()" broken the raycast? :)

So close, i can smell success!
#6
08/29/2009 (4:48 pm)
Hi Aleksander,
I haven't port that resource to T3D, but the castRayEA function was merely a copy of the original castRay function, I've just added the HBIndex param, so forget about setStatics & co, copy the original castRay function and then just add or modify the lines of code where HBindex is used.
#7
09/02/2009 (4:03 pm)
Ok, I tried that, but the game still crashes whenever it tries to do a castRayEA.
This is the transformed castRay -> castRayEA

bool TSShapeInstance::castRayEA(const Point3F & a, const Point3F & b, RayInfo * rayInfo, S32 dl, S32 HBIndex)
{
   // if dl==-1, nothing to do
   if (dl==-1)
      return false;

   AssertFatal(dl>=0 && dl<mShape->details.size(),"TSShapeInstance::castRay");

   // get subshape and object detail
   const TSDetail * detail = &mShape->details[dl];
   S32 ss = detail->subShapeNum;
   S32 od = detail->objectDetailNum;

   S32 start = mShape->subShapeFirstObject[ss];
   S32 end   = mShape->subShapeNumObjects[ss] + start;
   RayInfo saveRay;
   saveRay.t = 1.0f;
   const MatrixF * saveMat = NULL;
   bool found = false;
   if (start<end)
   {
      Point3F ta, tb;

      // set up for first object's node
      MatrixF mat;
      const MatrixF * previousMat = &mMeshObjects[start].getTransform();
      mat = *previousMat;
      mat.inverse();
      mat.mulP(a,&ta);
      mat.mulP(b,&tb);

     
      MeshObjectInstance * mesh = &mMeshObjects[HBIndex];

         

         if (&mesh->getTransform() != previousMat)
         {
            // different node from before, set up for this node
            previousMat = &mesh->getTransform();

            if (previousMat != NULL)
            {
               mat = *previousMat;
               mat.inverse();
               mat.mulP(a,&ta);
               mat.mulP(b,&tb);
            }
         }
         // collide...
         if (mesh->castRayEA(od,ta,tb,rayInfo, mMaterialList))
         {
            if (!rayInfo)
               return true;

            if (rayInfo->t <= saveRay.t)
            {
               saveRay = *rayInfo;
               saveMat = previousMat;
            }
            found = true;
         }
      
   }

   // collide with any skins for this detail level...
   // TODO: if ever...

   // finalize the deal...
   if (found)
   {
      *rayInfo = saveRay;
      saveMat->mulV(rayInfo->normal);
      rayInfo->point  = b-a;
      rayInfo->point *= rayInfo->t;
      rayInfo->point += a;
   }
   return found;
}
#8
09/03/2009 (12:56 pm)
I also changed:

In struct MeshObjectInstance : ObjectInstance

bool castRayEA( S32 objectDetail, const Point3F & start, const Point3F &end, RayInfo *info, TSMaterialList *materials);

But still, as i just look at the object with hitboxes the game just crashes.

I wonder if the error lies in TSShapeInstance::MeshObjectInstance::castRayEA

since if i just comment out 'EA' in if (mesh->castRayEA(od,ta,tb,rayInfo,mMaterialList))
then the game doesn't crash, but no collision either.

My TSShapeInstance::MeshObjectInstance::castRayEA function looks like this:
bool TSShapeInstance::MeshObjectInstance::castRayEA(S32 objectDetail, const Point3F & start, const Point3F & end, RayInfo * rayInfo, TSMaterialList* materials)  
 {  
      TSMesh * mesh = meshList[objectDetail];

      if (mesh)  
	  return mesh->castRay(frame,start,end,rayInfo,materials);  
     return false;  
 }

Any ideas? =)
#9
09/04/2009 (6:50 am)
You should check if in the preload function the HBindex[] is filled with meaningful values, that is something different from -1, because you have missed the
if (HBIndex == -1)       //No hit box to test   
    return false;

just below
if (dl==-1)   
      return false;

so, if it cannot find the hitbox meshes, it tries to access the &mMeshObjects[HBIndex], that crearly is undefined.

Then the function
bool TSShapeInstance::MeshObjectInstance::castRayEA
again, is a copy of the original function with just the visibility check removed, because the hitboxes are invisible meshes, so copy and modify the original one, indeed something has changed, now it is
TSMesh* mesh = getMesh( objectDetail );
not, like in your code
TSMesh * mesh = meshList[objectDetail];
that was true in TGEA. Although if everything before is right, this shouldn't create the problem. But now, it's better to use the getMesh function

Edit:
if after these checks, if it still crash, you need to debug it and see exactly why it crashes, because if everything is right, but the hb mesh are undefined, it shouldb't crash, just the collision doesn't work.
#10
09/04/2009 (1:23 pm)
Ok, im very close.

The reason it all crashed was because i set the objectdetail in
if (mShapeInstance->castRayEA(start, end, info, 0 ,mDataBlock->HBIndex[i]))

to 32. I Thought that worked since it at least gave me some feedback(in crashing). In showtool my model has detail-1, col-1, los-10.
objectdetail on detail-1 is 0, so i entered zero in the castRayEA function. However, my projectiles still fly straight trough it, not calling the second castRayEA true in castRayEA
if (mesh->castRayEA(od,ta,tb,rayInfo, mMaterialList))
         {
            if (!rayInfo)
               return true;

            if (rayInfo->t <= saveRay.t)
            {
               saveRay = *rayInfo;
               saveMat = previousMat;
            }
            found = true;
         }
soooo. I guess it can't find the hitboxes in the right detail layer or something. I'm so close guys! Help me with the final push! =)

edit:
the hitboxes are just regular rectangular boxes attached to the skeleton, in detail32. It should not be parented under col-1 right? Because then i can't get it to animate with the skeleton
#11
09/05/2009 (9:53 am)
Does anyone got a working hitbox system in T3D?
It would be of some comfort to know if the error is in my source or in my model!
#12
09/08/2009 (5:19 pm)
I'll check this out later today. I've been porting this resource through every version of TGE since 1.3, and I know I had to do something with that statics line to get it to play nice with T3D. I'll run some tests, make sure it's still working, and post what I did assuming it is. :P
#13
09/10/2009 (1:36 pm)
sounds great!
did you find out anything? :)
#14
09/16/2009 (8:45 am)
Any news on how to solve this? I assume "doing something with the statics" is something else than just commenting it out, like I did?
#15
10/06/2009 (11:59 am)
My associate spoke to a GarageGames employee the other day, and this is apparently supposed to be a stock feature in T3D, but had been overlooked.

Any news on when we can expect this to be added? As I previously mentioned, this is a critical component for our game, so we greatly anticipate it.
#16
10/06/2009 (6:59 pm)
Quote:My associate spoke to a GarageGames employee the other day, and this is apparently supposed to be a stock feature in T3D,

Oh, hmm very interesting, I've tried to get this hit box version to work but still have trouble getting things right.

So T3D is planned to contain a hit box system where a melee/missile system is planned. Anyone knows if its a modelled box-system, or code skeleton wrapper like the other one?

And what procedure is being planned for determening collisions, and collision origin ?
#17
10/25/2009 (7:56 pm)
I wouldn't know the exact cons and pros with the two different systems you are mentioning, but as long we are getting a more complex system that is in right now then i would be happy! =)

Anyone closer to finding out the "setStatics"-method and how to convert it to T3D?

I would certainly like to add it to a resource if I could get it working, just the last push now!
#18
11/18/2009 (6:54 pm)
any news on this? I haven't had much luck myself with this resource in T3D?
#19
11/19/2009 (5:55 am)
Hi, I've ported it to T3D and seems to work ok.
I'm thinking of updating the original resource or post the code here, but this won't happen before the next week
#20
11/19/2009 (8:32 am)
Thats great!! :)
Looking forward to it!
Page «Previous 1 2