Search Unity

Feedback Killed by last collision

Discussion in 'Scripting' started by TiToMoskito, May 1, 2021.

  1. TiToMoskito

    TiToMoskito

    Joined:
    Jan 28, 2014
    Posts:
    66
    Hi i have a question.
    I want to implement an kind of collision detection for my players, to see who killed the player by the last contact which directed him to death.
    There are two scenarios how a player can die in my game.
    1. Health <= 0
    2. Falls into water

    This is my code currently: https://ghostbin.co/paste/ha2o9hs
    But im not very happy with it, because when i hit a player XY, walk around for about 2 minutes and die, than player XY "has killed me", but i died because i jumped into the water.
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Filter your damage through a TakeDamage function on your player that also needs an owner or source parameter. Then you can remove the LastHit logic because it's built-in to your damage.
     
    Kurt-Dekker likes this.