How to make multiple body parts take damage?

For example, if my player gets shot in the leg, how would I play a limping animation and have him take a certain amount of damage based on where he got hit? By the way this is in javascript.

Basically,
what would I have to do to distinguish knee from arm from head when taking damage? Is there some script that says the location hit? Or something else. Anything would help.

P.S. Currently the game is in first person, but the character controller is a 3d model so I could change it to third person if needed.

Thanks in advance!

It depends of how you code your “bullet”.

But for a Ray for example, you can get the “contact point” position. Then you just have to make a script which says which part of the body is touched depends of where the contact point is on your hitbox.

(See Unity - Scripting API: RaycastHit for more info)

You can also achieve that with multiple hitbox : one per part of body (2 for arms, 2 for legs, one for body and one for head). So with this system you’ll know where the “bullet” hit the guy.

alright I’ll look into that, thanks