Hitbox question
by Ronald J Nelson · in Torque Game Engine · 03/14/2007 (4:58 pm) · 12 replies
I could use some advice on this. I have used this resource:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6538
I am trying to use it to determine within the player itself what the hitbox was that was struck. Now this would be easy if the player were hit by a projectile or some other moving object, but I want it to determine which hitbox was hit by wunning into a static object or interior.
Any ideas?
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6538
I am trying to use it to determine within the player itself what the hitbox was that was struck. Now this would be easy if the player were hit by a projectile or some other moving object, but I want it to determine which hitbox was hit by wunning into a static object or interior.
Any ideas?
#2
03/14/2007 (7:07 pm)
Well thats a good idea Stefan but with your first suggestion, which seems like it would be the best for me, I have no idea how to call the hitbox number from what I have seen in the code.
#3
03/19/2007 (12:16 pm)
Well Stefan I tried taking your advice and this is what I am testing it with. As you can see I also updated the code here so the vehicles would also pass the collided object's identity as well. However, I am not getting any results from the castRay. I know the remainder of my code that added the object's identity works fine because it tests perfectly. Any idea what it is I am doing wrong with the castRay?// Server side impact script callback
if (collided) {
// Pick the surface most parallel to the face that was hit.
Collision* collision = &mCollisionList.collision[0];
Collision* cp = collision + 1;
Collision *ep = collision + mCollisionList.count;
for (; cp != ep; cp++)
{
if (cp->faceDot > collision->faceDot)
collision = cp;
}
VectorF collVec = mRigid.linVelocity - origVelocity;
F32 collSpeed = collVec.len();
if (collSpeed > mDataBlock->minImpactSpeed)
{
Point3F startPos = getPosition();
Point3F endPos = (collVec - startPos) * 2;
RayInfo rayInfo;
if( mContainer->castRay( startPos, endPos, InteriorObjectType, &rayInfo ) )
{
Con::errorf(ConsoleLogEntry::General, "Impacted with a .dif and this is the hitbox : %d", rayInfo.HitBoxNum);
}
onImpact(collision->object, collVec);
}
}
#4
03/19/2007 (1:13 pm)
Thinking about it further, my idea is probably flawed in that when you have hit with the castRay and send another, it will not detect the hitbox unless it is a polylist. I *think*. I got a fever though, do not trust me.
#5
03/19/2007 (1:41 pm)
Anyone else not sick, sorry Stefan, got any suggestions?
#6
03/20/2007 (12:23 am)
Oh and another thing, its not the Hitbox code messing it up, Its actually the if statement. The castray itself isn't working. Its not meeting the condition of the if statement in the first place.
#7
03/20/2007 (1:17 am)
Does not that mean that it is not hitting anything? If so, it makes sense.
#8
03/20/2007 (5:36 am)
Well here is the funny part cause I figured it out last night, I had the start and end values backwards. Works mostly now.
#9
Now here are the console log results for a collision.
It always equals 0 which means even though the RayInfo, that is based off of the the Collision info, normally detects such things works well it isn't truly passing the material info. The materialPropertyMap.h is within my includes just as it is in the projectile code. Everything seems as if it should work, but it doesnt.
Can someone shed some light on this for me?
03/20/2007 (2:20 pm)
A bit of an update but it leads to further confusion for me. I changed my code up a bit to this:// Server side impact script callback
if (collided) {
//Damage Enhanced RJN start
// Pick the surface most parallel to the face that was hit.
Collision* collision = &mCollisionList.collision[0];
Collision* cp = collision + 1;
Collision *ep = collision + mCollisionList.count;
for (; cp != ep; cp++)
{
if (cp->faceDot > collision->faceDot)
collision = cp;
}
VectorF collVec = mRigid.linVelocity - origVelocity;
F32 collSpeed = collVec.len();
if (collSpeed > mDataBlock->minImpactSpeed)
{
if( collision->object->getTypeMask() & InteriorObjectType )
{
Con::errorf(ConsoleLogEntry::General, "Impacted with a .dif");
MaterialPropertyMap* pMatMap = static_cast<MaterialPropertyMap*>(Sim::findObject("MaterialPropertyMap"));
const MaterialPropertyMap::MapEntry* pMatEnt = pMatMap->getMapEntryFromIndex(collision->material);
if (pMatEnt)
{
Con::errorf(ConsoleLogEntry::General, "This is the material : %d", pMatEnt->matType);
}
}
onImpact(collision->object, collVec);
}
//Damage Enhanced RJN stopNow here are the console log results for a collision.
Impacted with a .dif This is the material : 0
It always equals 0 which means even though the RayInfo, that is based off of the the Collision info, normally detects such things works well it isn't truly passing the material info. The materialPropertyMap.h is within my includes just as it is in the projectile code. Everything seems as if it should work, but it doesnt.
Can someone shed some light on this for me?
#10
Had to do it with a reversed overlayed pair of raycasts and it works perfect everytime.
03/21/2007 (1:07 am)
Nevermind. I got it all working now. It passes the hitbox number and material information to the onImpact function perfectly now. Now for the much easier part of telling it to switch in the appropriate meshes based upon this info. Had to do it with a reversed overlayed pair of raycasts and it works perfect everytime.
#11
03/21/2007 (2:35 am)
So which technique is this? Cast a new ray and see if we hit one of the boxes, or something else?
#12
The only difference I can see with the onCollision method is that it notifies both ShapeBase objects of the collision if they are both objects that can move or are moving I suppose.
My reason for doing a combination with reverse coordinates is that I needed to get info from both objects. Basically with the Hitbox, I told the vehicle to look at itself.
03/21/2007 (5:07 am)
Well Stefan since I have a much more complicated material system in place I wanted also to be able to get my material information so I could make the correct collision debris based upon what I had Collided with. I am still finishing up the onCollision method but if you are just going to get the hitbox, use your collision vector as your starting coordinates and the position of the vehicle as the ending ones. I just added the standard rayinfo check with the condition for a VehicleTypeObject and it worked fine. The only difference I can see with the onCollision method is that it notifies both ShapeBase objects of the collision if they are both objects that can move or are moving I suppose.
My reason for doing a combination with reverse coordinates is that I needed to get info from both objects. Basically with the Hitbox, I told the vehicle to look at itself.
Torque Owner Stefan Lundmark