How to judge the hit part of one animal by a bullet

I am making one FPS unity game to hunt animal, and meet one problem: judge the hit part of one animal by a bullet, for example, the head, throat, trunk, limbs.

I know there is one tech to implement that: make one color texture to skin the animal, one color means one part. But searched google, little content found.

Btw, I don’t want to use the box collider, which is not accurate for the animal’s body.

32470-1.jpg

You can try a different approach, by using RaycastHit and accessing the hit objects texture coordinates.

You would set up your UVs in different quadrants on a single axis to represent the different areas to hit, head would be in u’s 0 to 1, neck is in u’s 1 to 2, torso is u’s 2 to 3, etc.

Read where the hit is, sort it, and you’ll know what was hit.

I used the method by Tzvier from reddit, tested, and got worked. Thanks everybody!

You can get the color from RaycastHit.textureCoord

Something like:

var getTx : Texture2D = hit.collider.renderer.material.mainTexture as Texture2D;   
var pixelUV = hit.textureCoord;
pixelUV.x *= getTx.width;
pixelUV.y *= getTx.height;      
var c : Color = getTx.GetPixel(pixelUV.x, pixelUV.y);

if(c == Color.red){
    ApplyDamage();
}