Shotting detection in different body parts

Posted By: DestroyTheRunner

Shotting detection in different body parts - 03/06/09 16:16

Hi

Some people might be tired of awnsering posts about this, sorry.
For what i could find, some people use vertex distance to define shots in different body parts, but I found that a bit innacurate, maybe because the way i've wrote the code or vertex distance is not the right way to do it.

So could anyone help me telling which way is the right way to detect, headshots, leg shot..... ?

thanks smile
Posted By: flits

Re: Shotting detection in different body parts - 03/07/09 08:34

the only thing i could think of is the closet bones ore make parts which you need to hit instead of the whole model
Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/07/09 09:07

I would go for the bone that the hit vertex is attached to.
I think this (UNTESTED) code should give satisfactory results.
(there is more in there than you'll need, but I put it in just in case)
Code:
STRING* HitBoneName = str_create("");
///
var dist = c_trace(whatever);
if(dist>0)   //make sure something WAS hit
{  if(hit.entity!=NULL);     //make sure we have an ENTITY
   {  ent_bonename(hit.entity, HitBoneName, hit.vertex);    //get the bone name
      if(str_len(HitBoneName)>0)   //make sure a BONE has been hit
      {  //"HitBoneName" is the name of the bone we've hit.
         //and if you name them simple like L_Arm_0, L_Arm_1, R_Arm_0, R_Arm_1, etc 
         //they'll be easy to spot with
         if(str_cmpni(HitBoneName,"L_Arm_")==1)
         {   //some part of LEFT ARM was hit      }
         else if(str_cmpni(HitBoneName,"R_Arm_")==1)
         {   //some part of RIGHT ARM was hit      }
         else if(str_cmpni(HitBoneName,"L_Leg_")==1)
         {   //some part of LEFT LEG was hit      }
         else if(str_cmpni(HitBoneName,"R_Leg_")==1)
         {   //some part of RIGHT LEG was hit      }
      }
      else
      {
         //entity has been hit but no bone is assigned to that vertex
      }
   }
   else
   {
      //there was a hit but NOT an entity
   }
}
else
{
   //NOTHING was hit
}

Posted By: DestroyTheRunner

Re: Shotting detection in different body parts - 03/07/09 13:13

hey guys thanks for your replies...
something I should've metioned before is that I still use A6 standard version which does not support bones. frown
but thanks if someday I upgrade to a higher version, the bones detection code will be surely put in use smile

does anyone has any other idea of how I could achieve this with my a6 standard version?
Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/07/09 14:24

Ive never used A6, so you'll need to to a bit of research on HOW to implement,
this but here is a concept that may be managable in A6.
1> Get the vertex nearest the 'impact" point.
2> Get the UV co-ordinate of that vertex.
3> Get the COLOR of the pixel at that UV co-ordinate from an unused,
color-coded skin(that is embedded in the MDL file). These colors relate to
which limb / body-part is in the actual uv-mapped skin.
4> From this color you know which body part was hit.

Get what I mean? Have a second, never-displayed skin with simple colors
painting the different body parts.
Posted By: DestroyTheRunner

Re: Shotting detection in different body parts - 03/07/09 15:40

wow...thats a freaking clever idea!
But Ill check the manual to see if the Part 3 of the concept is possible.
I'll let you know if i managed to work it out!

thanks smile
Posted By: Darkyyes

Re: Shotting detection in different body parts - 03/07/09 16:26

part 3 concept should work, if you store a color skin(arms red, feets blue, groin-stomach purple, chest green, head yellow) then through the hit detection it will check one of these colors, then if it hits red then it will hit the arms and damage lets say, 10, if it hits yellow which is head it will damage 100


through code you should be able to scan which color it detects on that skin, lets say its named hitskin then tell the code to scan that skin for the colors,
if you want random damage on head or the other parts, like this
if yellow(head)
78....100(or higher if you want "overkill" damage) then have like a random(20)

if you want random damage from different weapons this should be a function inside every type of weapon. just change the values inside the damage part.

this is just for filling out the third concept
Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/07/09 16:38

In case it may aid your search, here are the commands I would use in A7 - LiteC
Code:
Check before here that we have a sucessful hit on an entity.
1> var ClosestVertex = hitvertex;    //get the nearest vertex to the hit position
2> var UV[3];  vec_for_uv(UV, you, ClosestVertex);    //get the X,Y co-ordinate of that vertex in the UV map
3> BMAP* ColorMap = ent_getskin(you, 3);  //get the color-map skin, assume limb-color skin to be number 3
   var BmapType = bmap_lock(ColorMap);   //required to allow use of pixel_for_bmap
   var LimbPixel = pixel_for_bmap(ColorMap, UV[0], UV[1]);   //get the pixel from the colormap at UV position
   var LimbColor[3];   pixel_to_vec(LimbColor, NULL, BmapType, LimbPixel);    //convert pixel to a color vector
   bmap_unlock(ColorMap);   //free bmap now we are done with it
And now LimbColor contains the blue[0], green[1], and red[2] contents of the limb that got hit.
This code is a bit long winded and could easily be compressed, but Ive put it all in
to aid in your understanding of whats going on.
Remember, this is A7 stuff, but you may be able to find A6 equivalents for most of it.
Also, this code ISNT tested.

Best of luck...


Posted By: DestroyTheRunner

Re: Shotting detection in different body parts - 03/07/09 18:27

@darkyyes
thanks for you addon.. i already have an ideia about the damages and stuff...

@EvilSOB
thanks... thats what i was doing, searching for functions that would detect the color inside da skin... as soon as i get home, ill try them...

thanks you guys very much smile
Posted By: DestroyTheRunner

Re: Shotting detection in different body parts - 03/11/09 12:02

It worked!

the only problem is that my model contains several skins from several different mapped parts. eg. Head and throat, arms, legs....

and as far as i know i cant have the whole model mapped onto only one skin while the others skins have different vertices mapped ....
any work around?
Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/11/09 12:20

Hmm, damn.
OK, this a trial and error thing, but if you put SCAN_TEXTURE into the c-trace,
does the "tex_name" string change to a useful name of the string of the hit part?
Or does it just give the MDL-filename? If it gives the skin name, can you name
those in such a way to be able to extract the info you need?

OR
Does your textures have the alpha channel UNUSED? If it does, create alpha channels
on each skin and "paint" a specific alpha value over each body part.
That is replace our separate color-map skin with the alpha channel.
Youve just got to do it so the alpha channel never get displayed.
(never use the tranparent flag I believe...)
This will depend uon us getting different skin names from "tex_name" as the previous
paragraph tries for.

I can give more detail if this is managable.
Posted By: DestroyTheRunner

Re: Shotting detection in different body parts - 03/16/09 11:44

i understand. I think its managable, but i use as for shoot detection, a bullet using C_move and it doestn contain any scan_texture.I guess ill migrate to c_trace for shoot detection.
Ill try this at home and see if any of this 2 workarounds works!

thanks smile
Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/16/09 12:21

No need to migrate, just perform the c_trace after the c_move HITS the target.
Code:
...
you=NULL;
dist = c_move(me, reldist, NULL, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES);
if(you!=NULL)   
{  //hit some entity
   c_trace(me.x, you.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|SCAN_TEXTURE);
   //do something with the texture tex_name
}
...

Posted By: DestroyTheRunner

Re: Shotting detection in different body parts - 03/17/09 15:51

well..
the scan_texture thing returns the mdl file name, not the skin name. so it doesnt work for me.
and i failed trying the alpha channel thing.
I tried creating an alpha channel in photoshop and painted it with purple as a test. and it paints gray! not purple...
Does alpha channel has colors or is a color? or is just a 0 to 100 grayscale color? or is just a var from 0 to 100 relative to transparency?

frown
Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/17/09 16:56

var from 0 to 100 relative to transparency. 0 is transparent and 100 is solid.
The color you "paint" it in photoshop is only a reference. It has no "real" color.

Thats it Im afraid, Im out of ideas now. If I think of anything else, Ill post back.
Posted By: testDummy

Re: Shotting detection in different body parts - 03/17/09 17:58

Some time ago, ShoreVietam did something similar with bones and a home-brewed trace algorithm.
precise_shot.wdl - new version thread
Not surprisingly, the downloads in that thread appear to be dead.
Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/17/09 18:05

And after looking through the thread, it was bones-dependant.
If you had bones I could help eventually, but without Im stuck.
Posted By: DestroyTheRunner

Re: Shotting detection in different body parts - 03/18/09 17:22

hmmm due to my version, i cant use anything related to bones.

SOB
so ill try again the alpha channel way.

if put the alpha value
eg.:
25 for arms legs
50 for body
100 for head
to be retrieve by some function that detects the alpha value of the skin..
ok
but how will i paint this values in photoshop since its RGB or CMYK?
will be something like (R=255 + G=255 + R=255) = alpha 100?
Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/18/09 18:12

Nope, it is just another color ELEMENT (like Red or Green or Blue) that you cant actually see.
R=255, G=255, B=255, A= 100 = Solid White - (like a wall)
R=255, G=255, B=255, A= 50 = See-through White - (like frosted glass)
R=255, G=255, B=255, A= 0 = Invisible White - (like a clear gloss-free window)

I can describe the Photoshopping of the Alpha channel, BUT FIRST make sure
that A6 actually has a function to get the alpha info. I cant find any,
all the A7 functions that can read alpha are apparently new for A7, not in A6.

If you CAN find a function that CAN read the alpha value of a models skin,
let me know and I'll write instructions of how to set up the alpha channel and
paint your body-bits in photoshop.

FOOTNOTE: Alpha is actually 0-255, but is scaled down to 0-100 by 3DGS and photoshop.

Posted By: DestroyTheRunner

Re: Shotting detection in different body parts - 03/19/09 16:37

i see
i think this one works

pixel_to_vec(vector,var alpha,var format,var pixel);

Im not at home right to test it, but i think it should work!
Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/19/09 17:25

OK, kewl. The approximate code to use is like so.
Code:
BMAP* skin;
var UV[3], pixel, AlphaValue;

...
you=NULL;
dist = c_move(me, reldist, NULL, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES);
if(you!=NULL)   
{  //hit some entity
   c_trace(me.x, you.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES);
   vec_for_uv (UV, you, hitvertex);             //get UV co-ordinate of hit vertex
   skin = bmap_for_entity (you, you.frame);     //get skin at you's current frame
   format = bmap_lock(skin,0);                       //open BMAP for reading and get its format
   pixel = pixel_for_bmap(skin, UV[0], UV[1]);       //get the pixel of the UV co-ordinate
   bmap_unlock(skin);                                //close BMAP now its been read
   pixel_to_vec(NULL, AlphaValue, format, pixel);    //get pixels AlphaValue
   //do something with AlphaValue. Like
   switch(AlphaValue)
   {
      case 10:
         HitArms(you);
         break;
      case 25:
         HitLegs(you);
         break;
      case 50:
         HitTorso(you);
         break;
      case 100:
         HeadShot(you);
         break;
      default:
         Clipped(you);
   }
}
...

Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/19/09 17:53

Right, photoshop. Bear with me as Im doing this from memory, as I dont have Photoshop here,
and yours may be a different version. There may be some differences.

1> Open your texture in photoshop. (Original format un-important)
2> Use magic select tool with a color-range of 1(one), contiguous to select the UNUSED space
between your texture parts. All of it if possible, if its a bit broken up.
[dont de-select this mask till I say so, wink its important, we'll need it later]
2a> Optional - if you can find it, there is an option under the selection(?) menu called "Contract".
Its used to shrink the selection by xx number of pixels. Contract by 5 or so pixels.
3> Find the panel that normally shows the different layers on the image. It has a tab called "Channels".
Hit that and somewhere on this panel is a way to add new channels. Add one. It should call itself "Alpha 1".
Leave everything at default and just hit OK. You should now have a single, uniform color displayed.
4> Choose the Greyscale 0-100 pallet (happens automatic I think) and set the current color to WHITE (0%?)
5> Go to the selection menu and choose Invert, to invert our funky selection mask.
6> Fill in all our texture areas with our dead white till they are all done.
7> Now you can dump our selection mask. Basically All Done.
8> Now you can go through these Texture parts and give then different alpha levels.

REMEMBER the numbers 3dGS will see is the opposite of the 0-100 scale here in photoshop.
What you set to 10% here will be AlphaValue=90 in 3DGS.
ALSO REMEMBER you will need to make the RGB channel visible (on the channels panel) before you save.
When you save, TGA (32bit) is the best for this job. BMP's just get too big. And make sure the "Alpha Channels" box IS ticked.

That should get you started. Any questions, just ask.
Posted By: DestroyTheRunner

Re: Shotting detection in different body parts - 03/25/09 15:21

sorry sob... i sticked to the alpha problem and i forgot that my real problem is because i have several skins to my model.. and this color and alpha detection only works with the given skin.
eg.: bmap_for_entity (ent, ent skin);
so ill have to make the entire skin in one file, and then paint the parts with different colors.

thanks for the enlightment. i really appreciate! smile
Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/25/09 20:57

Gah! Me too. Oh well, one skin it is.

"Actually, no, wait a minute, whats that switch there..."

Do you think this is managable, create a duplicate SET of skins in each model, that are a low-res hit-point-color only skins.
When we have detected a hit, swap skins, c_trace(using SCAN_TEXTURE) to get the color at the target point(through TEX_COLOR),
then swap the skins back.

If its done inside 1 frame it should work, but it all depends on IF the skin swapping can be done quick enough in A6,
cause I have no idea how it switches between skins on a multi-skin model. I never have had to.

BUT do some testing of retrieving tex_color first, the manual says that it gets "color of the lightmap at the hit position."
Im not clear on how this works with multi-skin models though. It may not give us what we want...
Posted By: DestroyTheRunner

Re: Shotting detection in different body parts - 03/26/09 01:02

lol!

SOB actually the method that we achieved until now, works with 2 skins.
The first one is my real model skin( all grouped and packed in one TGA file) and the other one is a copy of the model real skin but in colors, where it is the head, its painted red, where its an arm its painted blue... and so on...
Lets say that my model real skin is 0 and the color value skin is 1.

So i can search in my skins by knowing that the color value skin is 1.. so
bmap_for_entity (stupid_ent, 1); //color value skin

so... if i have 3 real skins(head, body and arms&legs), i would need more 3 color value skins.
so this methods works GREAT with one real skin, but fails with anything more than that, since for every real skin your model got, i would need an extra color value skin!


ps1. SCAN_TEXTURE in c_trace only gives the texture name if it is a level block. if it is an entity,sprite or terrain it gives the model/bmap file name.

ps2. From the manual:
Quote:

The variable tex_light gives the shadow map brightness (0..255) at the hit position in the level, tex_color gives the light color and tex_fog gives the fog / albedo value.


tex_color doesnt work of me either.

Im almost completely convinced that as long as i dont buy something more than A6 standard. Ill have to have my models with only one skin if i want to have a body hit detection.
Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/26/09 01:13

Its not clear here, but are you using the SCAN_TEXTURE flag in the c_trace, when testing "tex_light"and "tex_color"?

The way I interpret the A7 manual, it seems you need to use the SCAN_TEXTURE flag otherwise it doesnt update the variables tex_light, tex_color.
Posted By: DestroyTheRunner

Re: Shotting detection in different body parts - 03/26/09 01:44

what i meant with 'doesnt work' means actually that its not usefull for me..
Scan_texture gives the model name and not the texture. and even if updates tex_light it wont work/be useful for me for what i need.

sorry for the complication!
Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/26/09 02:00

But what about the tex_color? Does that (when updated by SCAN_TEXTURE) give
the pixel color of the hit skin, or something else? The manual isnt clear.

And you werent complicating, I was just trying to read between the lines.
Posted By: DestroyTheRunner

Re: Shotting detection in different body parts - 03/26/09 16:25

tex_color gives the light that is reflected or inflicted in the model, or something like this.
Still, i dont need tex_color because i already managed to get the color of the skin through the given xy coordinade.
The only problem for me is still that this method only works with one real skin and one color value skin.
frown

anyway thanks SOB for the help. Ill show you the results later when my game became playable.
Posted By: EvilSOB

Re: Shotting detection in different body parts - 03/26/09 21:22

OK good luck.

Also remember, the hit-color skin does not need to be as high detail as the real texture.
Say your real texture is 1024x1024, your hit-color skin can be 128x128 and it will get
"stretched" across the same UV mapping co-ordinates. It only need to have a
high enough resolution to make sure the right hit-colors are on the right body parts.
You can just let the colors bleed into the un-used space between body parts with no fear,
or just fill that unused space with the lowest hit-color value so everything is covered.
Posted By: DestroyTheRunner

Re: Shotting detection in different body parts - 03/27/09 11:17

wow.. i didnt know that!
That will save some memory!

thanks a lot smile
Posted By: ShoreVietam

Re: Shotting detection in different body parts - 04/13/09 08:00

I wrote a body-part-detection once for my multiplayer western shooter, because the model hull is not being updated through animation cycles.

This "precise_shot.wdl" uses bones, too.
It makes a mathematical check whether a shot from a certain point to a certain direction passes a bone in a certaint distance or not.

Values like target vector and hit bone can be accessed, but you have to cross-check with a trace if there was soemthing in the way and call the function itself through a you=ent_next() loop for each entity.

It worked quite well, here's the thread:
precise_shot for ego shooters

The demo is not online any more, but the script file is.
Within the file there is a comment-description on how to use it (if still needed). ^^




Posted By: MegaMarioDeluxe

Re: Shotting detection in different body parts - 04/21/09 07:59

You could add invisible blocks that act as "collison detectors".
© 2024 lite-C Forums