getting bone name hit by c_trace with USE_BOX

Posted By: Reconnoiter

getting bone name hit by c_trace with USE_BOX - 01/07/18 15:12

Howdy,

I am trying to detect which limb gets hit on an attack (that uses c_trace with USE_BOX). The USE_BOX prevents that c_trace sets hit.vertex or hit.x, and so I cannot use ent_bonename since I am missing the vertex number and also the position of impact to get the vertex number (ent_nextvertex).

So what I a good alternative to get the closest vertex number on impact that is reasonable fast?
I have been thinking of either cycling through all the vertices of the entity that gets hit but that is a bit to slow I think (the entity is high poly) or perhaps use a 2nd c_trace without USE_BOX, which would be faster I guess(?). Or is there perhaps a better option?
Posted By: rayp

Re: getting bone name hit by c_trace with USE_BOX - 01/07/18 17:09

Set scan_texture flag in c_trace.

If u have old data in hit vertex u dont want to overwrite u could store hit.x in my.skill's for example

Also u could setup hit groups in med and check which group was hit bei c_trace. Superku once made an example of hit detection.
Posted By: Reconnoiter

Re: getting bone name hit by c_trace with USE_BOX - 01/07/18 17:58

Hi, Scantexture does not work with usebox i think.
Posted By: rayp

Re: getting bone name hit by c_trace with USE_BOX - 01/07/18 19:37

Just tryed. With the following code i receive a bone handle...have to mention i did not check whats in the handle laugh

Code:
#define health skill100

void test_trace(){
   draw_text ("active", 10,10, vector(255,0,0));
   var sight = 300;                                                         // i can see this far
   VECTOR tpos;
   vec_for_angle (tpos, vector (my.pan, my.tilt, my.roll));
   vec_scale     (tpos, sight);
   vec_add       (tpos, vector (my.x, my.y, my.z));
   trace_mode = IGNORE_ME | IGNORE_PASSABLE | USE_BOX | SCAN_TEXTURE | IGNORE_SPRITES;
   c_ignore (1, 0);
   c_trace  (vector (my.x, my.y, my.z), tpos, trace_mode);
   if (HIT_TARGET){
      if (you) if (ent_bonename (you, NULL, hit.vertex)) draw_text ("Bone handle returned", 10, 20, vector (255,0,0));
      draw_point3d (target.x,vector(50,50,255),100,3);
   }
}

action hero{
        my.health = 100;
        my.group  =   1;
	...
	..
	.
	while (my.health > 0){
		test_trace();
                ...
                ..
                .
		wait (1);
	}
	.
	..
	...
}


The traced model has POLYGON flag set.
Posted By: Reconnoiter

Re: getting bone name hit by c_trace with USE_BOX - 01/08/18 13:07

Ty for fast reply. Well the problem is that it returns the same bone name when hitting different parts/bones (polygon hulls), the manual also states that usebox is mutually exclusive with scantexture. I really need usebox though, since the entities have some thin shapes etc otherwise attacking would be to annoying.

Edit- I noticed that hit.x is actually updated, but the vertex number not. And "var vertex_num = ent_nextvertex(you, hit.x);" works only for terrains it seems. So I just need to find an effective way of finding the closest vertex to the hit.x ...
Posted By: DriftWood

Re: getting bone name hit by c_trace with USE_BOX - 01/08/18 17:09

The solution is like Superku first hitbox design. He attached many invisible boxes to the model. You can make the boxes thicker on your thin body parts. When shooting you ignore the bbox of the entity and use these hitboxes.
It can be found in an old AUM.
Furthermore, you can use the poly of the entity and only add these hitboxes for the thin parts of the entity body.
Posted By: Superku

Re: getting bone name hit by c_trace with USE_BOX - 01/08/18 20:26

Thanks for the recommendation but I advise against using that old multiple boxes approach.
You could use a very low poly character for collision only but with the same bones/ skeleton. When you call your hitscan weapon code copy the animation to the invisible low poly mesh, call c_updatehull (?) and c_trace without USE_BOX.
I once wrote the following anim copy function, could be optimized probably:

Code:
void ent_anim_copy(ENTITY* eTarget, ENTITY* eSource)
{
	int i,numBones,hparent;
	ANGLE angle,angle2,angle3,eSourcePanInv;

	numBones = ent_bones(eSource);
	ent_bonereset_all(eTarget);
	ang_diff(&eSourcePanInv,nullvector,&(eSource->pan));
	for(i = 0; i < numBones; i++)
	{
		ang_for_bone(&angle,eSource,i+1); // use bone handles/ indices instead of names
		ang_add(&angle,&eSourcePanInv);
		hparent = ent_boneparent(eSource,NULL,i+1);
		if(hparent > 0)
		{
			ang_for_bone(&angle2,eSource,hparent); // eTarget's bone is already rotated by parent bone's rotation => undo it!
			ang_add(&angle2,&eSourcePanInv);
			ang_diff(&angle3,nullvector,&angle2); // best way to do this? I doubt it.
			ang_add(&angle,&angle3);
		}
		ent_bonerotate(eTarget,i+1,&angle);
	}
}

Posted By: rayp

Re: getting bone name hit by c_trace with USE_BOX - 01/10/18 17:37

Its like always. Everytime you need a workaround or something isnt working like it should. The attempt with bonename sounded pretty good for me.

Edit
I once simply checked height of hit to decide if leg body or head was hit to use three different anims. Of course this weak system visually cant compare to hit detection with ragdoll but it was easy fast and looked pretty cool
Posted By: 3run

Re: getting bone name hit by c_trace with USE_BOX - 01/10/18 17:42

Originally Posted By: Reconnoiter
Scantexture does not work with usebox i think.
Hey

It works for me pretty well!
Posted By: Reconnoiter

Re: getting bone name hit by c_trace with USE_BOX - 01/11/18 13:05

Thanks for you all replying.

Originally Posted By: Superku
Thanks for the recommendation but I advise against using that old multiple boxes approach.
You could use a very low poly character for collision only but with the same bones/ skeleton. When you call your hitscan weapon code copy the animation to the invisible low poly mesh, call c_updatehull (?) and c_trace without USE_BOX.
I once wrote the following anim copy function, could be optimized probably:

Code:
void ent_anim_copy(ENTITY* eTarget, ENTITY* eSource)
{
	int i,numBones,hparent;
	ANGLE angle,angle2,angle3,eSourcePanInv;

	numBones = ent_bones(eSource);
	ent_bonereset_all(eTarget);
	ang_diff(&eSourcePanInv,nullvector,&(eSource->pan));
	for(i = 0; i < numBones; i++)
	{
		ang_for_bone(&angle,eSource,i+1); // use bone handles/ indices instead of names
		ang_add(&angle,&eSourcePanInv);
		hparent = ent_boneparent(eSource,NULL,i+1);
		if(hparent > 0)
		{
			ang_for_bone(&angle2,eSource,hparent); // eTarget's bone is already rotated by parent bone's rotation => undo it!
			ang_add(&angle2,&eSourcePanInv);
			ang_diff(&angle3,nullvector,&angle2); // best way to do this? I doubt it.
			ang_add(&angle,&angle3);
		}
		ent_bonerotate(eTarget,i+1,&angle);
	}
}

, interesting idea, will have to think a bit about this one (in combination with painting gore / decals etc that I currently use on my current trace).

Originally Posted By: 3run
Originally Posted By: Reconnoiter
Scantexture does not work with usebox i think.
Hey

It works for me pretty well!

, for me it definitely doesn't work, it keeps returning the same bonename regardless of where the target entity is hit.

Originally Posted By: rayp
Edit
I once simply checked height of hit to decide if leg body or head was hit to use three different anims. Of course this weak system visually cant compare to hit detection with ragdoll but it was easy fast and looked pretty cool
, tnx I thought of something similar and I think it could work pretty decently as a lite limb detection system. :-)

Originally Posted By: DriftWood
The solution is like Superku first hitbox design. He attached many invisible boxes to the model. You can make the boxes thicker on your thin body parts. When shooting you ignore the bbox of the entity and use these hitboxes.
It can be found in an old AUM.
Furthermore, you can use the poly of the entity and only add these hitboxes for the thin parts of the entity body.
, tnx but this would become a bit complicated in my case since I have quite a bit of different models (and of various shapes). In the latter case of adding boxes to the models, I tried this earlier but it gives some problems with painting gore / decals etc on the target entities.
Posted By: Superku

Re: getting bone name hit by c_trace with USE_BOX - 01/11/18 14:43

You could make a USE_BOX trace first, then, on a hit, do a SCAN_TEXTURE (without USE_BOX) trace to some target like endpoint:

c_trace(from,to,USE_BOX);
if(trace_hit)
{
vec_diff(temp,target,from);
vec_scale(temp,1.05); // make sure it reaches far enough
vec_add(temp,from);
c_trace(from,to,SCAN_TEXTURE);
}
Posted By: Reconnoiter

Re: getting bone name hit by c_trace with USE_BOX - 01/14/18 14:08

Ty for the suggestion.
I went with the same approach as Rayp went, which works (surprisingly) decent for humanoids. I use vec_to_ent to transform the hit.x(yz) to local coordinates than compare with minxyz/maxxyz etc. I can check for torso, head, (roughly) arms and legs this way.
© 2024 lite-C Forums