The Hitbox Tutorial
by Josh Albrecht · 11/08/2001 (8:41 am) · 23 comments
Download Code File
The whole purpose here is to create more accurate hit detection. We do this by creating a "hitbox" for each limb. This "hitbox" is simply an invisible box that encases a limb. The hitbox always remains around the limb, despite whether it animates or not. Collision detection (seeing if one object hit another) can easily be done against a box, so hitboxes make colliding with specific limbs much more accurate, and easier than any other method I could think of.
Hitboxes are both relatively precise, and use little processing power.
This tutorial also shows how to collide melee weapons against hitboxes(the theory behind it will be explained later). It DOES NOT show how to do this with projectile weapons, but if you read the whole thing and understand it, you should easily be able to figure that out. Or maybe someone else can add on to my tutorial....
The full tutorial & source (in txt format) is attached to this resource. Download it to get started!
The whole purpose here is to create more accurate hit detection. We do this by creating a "hitbox" for each limb. This "hitbox" is simply an invisible box that encases a limb. The hitbox always remains around the limb, despite whether it animates or not. Collision detection (seeing if one object hit another) can easily be done against a box, so hitboxes make colliding with specific limbs much more accurate, and easier than any other method I could think of.
Hitboxes are both relatively precise, and use little processing power.
This tutorial also shows how to collide melee weapons against hitboxes(the theory behind it will be explained later). It DOES NOT show how to do this with projectile weapons, but if you read the whole thing and understand it, you should easily be able to figure that out. Or maybe someone else can add on to my tutorial....
The full tutorial & source (in txt format) is attached to this resource. Download it to get started!
About the author
#2
02/25/2002 (6:24 pm)
I have read your tutorial and found it pretty usefull. However (and PLEASE do not take this as criticism!!!), why not just create collision nodes for the individual pieces of the model?
#3
Now every function is defined. We still need to call the updateHits function however. This is done around line 1142 of player.cc. The code there should look like this(put our function where the comment indicates):
if (!isGhost()) {
// Animations are advanced based on frame rate on the
// client and must be ticked on the server.
updateActionThread();
updateAnimationTree(true);
updateHits();
//LOOK! THERE IS OUR FUNCTION! :)
}
so i just skipedit hoping the compile errors would tell me somthing ,,,but i dont get it
here are the compile errors
F:\torque\engine\game\player.cc(2373) : error C2601: 'updateHits' : local function definitions are illegal
F:\torque\engine\game\player.cc(2481) : error C2601: 'CheckSwing' : local function definitions are illegal
maybe if some one that has this tut working could show me there player.cc i could get it working
thanks
02/28/2002 (5:39 pm)
help,,,,i dont understand this part of your tutNow every function is defined. We still need to call the updateHits function however. This is done around line 1142 of player.cc. The code there should look like this(put our function where the comment indicates):
if (!isGhost()) {
// Animations are advanced based on frame rate on the
// client and must be ticked on the server.
updateActionThread();
updateAnimationTree(true);
updateHits();
//LOOK! THERE IS OUR FUNCTION! :)
}
so i just skipedit hoping the compile errors would tell me somthing ,,,but i dont get it
here are the compile errors
F:\torque\engine\game\player.cc(2373) : error C2601: 'updateHits' : local function definitions are illegal
F:\torque\engine\game\player.cc(2481) : error C2601: 'CheckSwing' : local function definitions are illegal
maybe if some one that has this tut working could show me there player.cc i could get it working
thanks
#4
I have this working fine (very cool), but I was wondering how to use this with an actual melee weapon. I see the players arm is being used as the weapon for the tutorial here. I guess I'm just not sure how to make a seperate weapon use the tip/handle points. This is probably simple, but I'm not seeing it at the moment. Any ideas?
I also noticed this doesn't seem to work on bots. Not sure why though. It works fine in multi-player.
@Ace, I'm using the HEAD version of the engine from 7-02-02 at the moment, but could show you my player.cc file if you'd like.
-Sabrecyd
07/08/2002 (5:19 am)
Josh,I have this working fine (very cool), but I was wondering how to use this with an actual melee weapon. I see the players arm is being used as the weapon for the tutorial here. I guess I'm just not sure how to make a seperate weapon use the tip/handle points. This is probably simple, but I'm not seeing it at the moment. Any ideas?
I also noticed this doesn't seem to work on bots. Not sure why though. It works fine in multi-player.
@Ace, I'm using the HEAD version of the engine from 7-02-02 at the moment, but could show you my player.cc file if you'd like.
-Sabrecyd
#6
I'll email it to you tomorrow. I don't have it with me at the moment. Just so you know there are some other things in there I've added, so the line #'s might not match yours.
07/08/2002 (6:53 am)
Ace,I'll email it to you tomorrow. I don't have it with me at the moment. Just so you know there are some other things in there I've added, so the line #'s might not match yours.
#7
Just thought I'd post this in case you want to try this before tomorrow night. Plus might save you a little work.
Here's what the section of code you asked about above looks like before the change:
Here's after the change:
You really just need to add the one line - updateHits();
-Sabrecyd
07/08/2002 (12:18 pm)
Ace,Just thought I'd post this in case you want to try this before tomorrow night. Plus might save you a little work.
Here's what the section of code you asked about above looks like before the change:
if (!isGhost()) {
// Animations are advanced based on frame rate on the
// client and must be ticked on the server.
updateActionThread();
updateAnimationTree(true);
}Here's after the change:
if (!isGhost()) {
// Animations are advanced based on frame rate on the
// client and must be ticked on the server.
updateActionThread();
updateAnimationTree(true);
updateHits();
//LOOK! THERE IS OUR FUNCTION! :)
}You really just need to add the one line - updateHits();
-Sabrecyd
#8
if you have a chance send me your player.cc
Ace_NoESCape@planetquake.com
and maybe i'll then get it to work
thanks
07/08/2002 (5:21 pm)
i think i didnt udersatnd where that bit of code should be inserted (it was a long time since i tried this, tut. if you have a chance send me your player.cc
Ace_NoESCape@planetquake.com
and maybe i'll then get it to work
thanks
#11
You asked the question, "I see the players arm is being used as the weapon for the tutorial here. I guess I
05/22/2003 (12:36 pm)
Sabrecyd,You asked the question, "I see the players arm is being used as the weapon for the tutorial here. I guess I
#13
06/05/2003 (11:01 am)
Thank you Sabrecyd, I got that and I will try this out.
#14
I had working very good hitboxes, but when I changed my server to "dedicated server", you can see the player with the sword but is not registered, so there isn't collision.
I think that I have to send the registerWeapon to client side (with commandToClient), but until this moment I haven't find the correct way.
Somebody is working wiht dedicated server and hitboxes?,
I need some ideas please.
Thanks!.
08/09/2004 (8:18 am)
Hello, great Tutorial!. I had working very good hitboxes, but when I changed my server to "dedicated server", you can see the player with the sword but is not registered, so there isn't collision.
I think that I have to send the registerWeapon to client side (with commandToClient), but until this moment I haven't find the correct way.
Somebody is working wiht dedicated server and hitboxes?,
I need some ideas please.
Thanks!.
#15
getNodeTransform is an undeclared indentifer
can you offer any help on what i could be doing wrong
im currently running Version 1.3 of Torque
i have found a few versions of getNodeTransform but none that have the same input variables.
after some searching on the forums i found this:
//--------------------------------------------------------------// Get node transform
MatrixF ShapeBase::getNodeTransform( StringTableEntry nodeName )
{
TSShape *shape = mShapeInstance->getShape();
if (!shape)
return MatrixF(true);
S32 node = shape->findNode( nodeName );
if (node < 0)
return MatrixF(true);
return mShapeInstance->mNodeTransforms[node];
}
01/18/2005 (6:46 am)
I keep getting an error while trying to implent this and that error is that:getNodeTransform is an undeclared indentifer
can you offer any help on what i could be doing wrong
im currently running Version 1.3 of Torque
i have found a few versions of getNodeTransform but none that have the same input variables.
after some searching on the forums i found this:
//--------------------------------------------------------------// Get node transform
MatrixF ShapeBase::getNodeTransform( StringTableEntry nodeName )
{
TSShape *shape = mShapeInstance->getShape();
if (!shape)
return MatrixF(true);
S32 node = shape->findNode( nodeName );
if (node < 0)
return MatrixF(true);
return mShapeInstance->mNodeTransforms[node];
}
#16
11/13/2005 (3:15 am)
i had the same problem as mike, but where would you put that function
#17
thank in advance...
03/06/2007 (8:14 pm)
I hear that this resource is old ( I have TGE 1.5). Is there a new resource that has been made regarding hotboxes..because i was thinking of making a game where you have separate heaths (for example: head, neck, arm, hand, etc.).thank in advance...
#18
Really looking forward to getting this working...
06/22/2007 (9:53 am)
This is awesome. I integrated it rather painfully (I stupidly decided to manually type in every line, resulting in about 100 errors relating to my typos...), but I learned a lot. It compiled without a whisper, but when I run torqueDemo (1.5.2, fast relight debug build), I get an immediate crash with an unhandled exception in platformMemory.cc in function treeRemove.Really looking forward to getting this working...
#19
Im currently adding this, or at least trying to, into tgea 1.7.1+afxa and ran into the (obvious coming wall) of tutorial not at all being like code, etc. But Im still fighting it, trying to make it work ;)
Im having some serious problems with it though and wondered if anyone else had/is/are onto this as well?
10/30/2008 (2:55 am)
Heyas!Im currently adding this, or at least trying to, into tgea 1.7.1+afxa and ran into the (obvious coming wall) of tutorial not at all being like code, etc. But Im still fighting it, trying to make it work ;)
Im having some serious problems with it though and wondered if anyone else had/is/are onto this as well?
#20
11/20/2008 (11:02 am)
... 
Torque Owner Josh Albrecht