Search Unity

How to make multiple body parts take damage?

Discussion in 'Scripting' started by 3, Sep 17, 2012.

  1. 3

    3

    Joined:
    Sep 16, 2012
    Posts:
    387
    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!
     
  2. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    222
    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 http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit.html 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.
     
  3. 3

    3

    Joined:
    Sep 16, 2012
    Posts:
    387
    alright I'll look into that, thanks