How to "Character dies if hit on the head" ?

Hi, i need my character, with character controller as a component, to die if hit on the “head” ( that is actually the “top” considering he is a rectangle) by a falling object, that’s affected with gravity, and needs to.

I also need that my char will keep on being able to jump over this falling objects once he avoided them, so he should be able to touch them on the sides and on the top.
I’m asking for some help, possibily a javascript script, if you can.

Tell me if you need more info, thanks ^^

Create a collider to represent hit boxes for the head and the rock and set the rock collider to a trigger. Only enable to collider if the rock is falling. Then, on your character, handle the OnTriggerEnter or OnTriggerEnter2D event depending on whether you used 3d or 2d colliders.

make a trigger cube for the head, parent it to the player, and do something along the lines of…


     //c#

     void OnTriggerEnter () {
          if(thisIsThatPhysicalActiveObjectThatKills){
               die();
          }
     }

     //javascript

     function OnTriggerEnter () {
          if(thisIsThatPhysicalActiveObjectThatKills){
               die();
          }
     }

The cleanest and a pro approach would be to work with a 2D texture and compare a ray cast hit along an x-y coordinate of a UV Layout

It is easy.

  1. Create a another collider on the head, or create a empty gameobject and add to it a collider which will be trigger. Then add a tag to it with name “bullet”

  2. If you’re using bullets to shoot[instantiating objects] you need to check if the bullet goes through the collider you created. So this is the script:

    function OnTriggerEnter(col : Collider){
    if(col.gameObject.tag == “bullet”){
    killPlayer();
    }
    }
    So that pretty much it, for bullets. :slight_smile:

Hope it helped :wink: