Game Development Community

Anyone want locational damage? :)

by Josh Albrecht · in Torque Game Engine · 10/13/2002 (4:38 pm) · 14 replies

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3374


(Hopefully that link works)

I made a 'hitbox' tutorial a long time ago, and I promised to release an updated version. Well, here it is, a few months late. Sorry about the wait, but sometimes that dam "real-life" thing gets in the way of coding. :(

It may not be perfect, but I'd appreciate it if a few people tried it and got back to me with any bugs, or improvements. I know that it's not perfect right now, but I'll fix the small imperfections and update it again once I get some feedback.

#1
10/13/2002 (5:04 pm)
The download link isnt working correctly. Thanks a bunch for this, I plan on implementing something like this once I get the hang of how the script and code flow together.

-Jared
#2
10/13/2002 (5:26 pm)
Ok, well I just submitted the resource, so until they approve it, it may not work correctly.
#4
10/15/2002 (11:21 am)
Oh my, sorry about that.

Oh, and if you are interested, be sure to read the comments first.
#5
10/15/2002 (11:23 am)
why not a standard compression format like zip?
#6
10/15/2002 (12:26 pm)
rar IS a standard! I use it exclusively.

That is the beautiful thing about standards, there are so many to choose from :)

www.rarlab.com/rar_archiver.htm
#7
10/15/2002 (2:25 pm)
There, I reposted it as .zip. I was just to lazy to change the format before. :) Plus, I think people should try winrar, it is alot better than winzip.
#8
10/23/2002 (10:03 am)
I usually use winzip, but winrar does seem better. I have both installed now.

Josh, I got everything compiled and working (seems like it anyway). Have you tried this code using the bots? I'm using the current HEAD engine right now. With the debugger line rendering left on, the red hitboxes align fine but the black and yellow hitboxes don't seem to animate correctly and are bunched up outside the blue bounding box of the bot (default blue guy). All the hitboxes align ok on the player. Have you seen this happening? I can send you a .jpg if that would help show what I mean.

The other question I had was about using projectiles. How are they used to indicate the hit location like the melee weapons do?

Everything else seems to work great so far. Excellent work!

-Sabrecyd

edit: Josh, I sent you an email with a pic to check out.
#9
10/23/2002 (12:02 pm)
@Sabre: you would have to add a couple of parameters to some functions.. specially the collision ones... not sure if Josh did that on his tutorial... It's been some time since I got his code and I completely changed it... in my game I have locational damage working perfectly with projectiles atm.

I have something like this:
function RifleProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal,%hitBoxName) { ... };
Where hitBoxName is the name of the hitbox, for example Bip01 Head or Bip01 Spine... from there what you can do is do a simple switch block to determine where the projectile hitted and how much damage it should deal, for example:
switch$(%hitBoxName)
      {
         case "Bip01 Head":
            %col.damage(%obj, %pos, 20, "M3GreaseGunBullet");

         case "Bip01 Spine":
            %col.damage(%obj, %pos, 20, "M3GreaseGunBullet");

Of course you'll have to modify Projectile.cc where onCollision script function is called to add the hitboxName.... let me know if you have trouble doing this and I'll post that part of the code too.
Hope that helps :)
#10
10/23/2002 (12:14 pm)
Hey thanks Xavier. You were the initial test guy weren't you :) What you have there certainly makes sense. That's basically how the melee stuff works (I think) with the added %loc in the example instead of %hitBoxName like your using for the projectiles. I like using the switch statement too. I'm using that for some death animation stuff now. Combined with the hitbox stuff it would be much better.

If you wouldn't mind posting that section of code when you have time, that would be great. I'll take a look tho either way and see if I can make it work on my own first.

Thanks again,
-Sabrecyd
#11
10/23/2002 (5:13 pm)
Ok, I hope not to miss anything..
In Projectile.cc, Projectile::processTick there's a part of the code that has to be added there... Mine looks like this:
// Get the object type before the onCollision call, in case
            // the object is destroyed.
            U32 objectType = rInfo.object->getType();

            if(mSourceObject)
               mSourceObject->enableCollision();

            // New code below
			if(isServerObject() && (rInfo.object->getType() & ShapeBaseObjectType))
			{
				ShapeBase *obj= dynamic_cast<ShapeBase*>((NetObject *)rInfo.object);

				S32 aHBID;
				if(obj->checkProjectileCollisionHB(oldPosition, newPosition, mCurrVelocity, rInfo.point, aHBID))
				{
					onCollision(rInfo.point, rInfo.normal, rInfo.object, obj->mHitboxes[aHBID].nodeName);
					explode(rInfo.point, rInfo.normal, objectType );
				}
				else
				{
					onCollision(rInfo.point, rInfo.normal, rInfo.object, "");
					explode(rInfo.point, rInfo.normal, objectType );
				}
			}
			else
			{
				onCollision(rInfo.point, rInfo.normal, rInfo.object, "");
				explode(rInfo.point, rInfo.normal, objectType );
			}
	    //Old code below		
            if(mSourceObject) 
               mSourceObject->disableCollision();
            break;
         }

What this does is pass a new parameter to the onCollision function which is the name of the hitbox... pretty simple.. also it's a bit modified in other things too... since i had this for some time i made LOTS of changes, enhancements, bug fixes, etc.... might not look like the original, not sure, i dont remember :)
Ok now let's look at Projectile::onCollision shall we? :)
Let me see..... here it is....
Ok the function definition should look like this:
void Projectile::onCollision(const Point3F& hitPosition,
                             const Point3F& hitNormal,
                             SceneObject*   hitObject,
   			     const char*	hitBoxName)
Make sure to change it both in the function itself and in the declaration in the header file please :)
Now inside the function check for the script function call and replace it:
Con::executef(mDataBlock, 7, "onCollision",
         scriptThis(),
         Con::getIntArg(hitObject->getId()),
         Con::getFloatArg(mFadeValue),
         posArg,
         normalArg,
		 hitBoxName);

Ok, I think that's all... hope it's useful :)

EDIT: oh.. and yes... i do know that there's a couple of rebundant lines on the first code post... sorry, was a quick fix i did and never cleaned it up.
#12
10/24/2002 (5:28 am)
Thanks very much Xavier.
I'm sure it will be useful. I'll try it out tonight (or today at work if I can). I was looking at it last night and could get part of it working but not quite correctly. I was missing some of the aHBID code in the process tick function - kinda important ;). I wasn't calling the checkProjectileCollisionHB function the right way from how it looks. The onCollision and script part I had seemed ok. Someday maybe I'll get this stuff down better.
#13
10/24/2002 (6:35 am)
Hey guess what..works great! Yeah, already tried it out at work. Only had a couple minor errors initially.

1 - added const char* to virtual void onCollision in the projectile.h file.
2 - added attachedTransform to the 4th parameter of the function call checkProjectileCollisionHB in the onCollsion function in projectile.cc. It needed 5 parameters. Not sure if it would be better to use something else there. The attachedTransform is for the "sticky" projectiles.

After that though getting the script stuff to work was a snap. Thanks again for the help Xavier :)