Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Enemy does not kill the player when on contact anymore

Discussion in 'Physics' started by Polarfist1, Sep 12, 2021.

  1. Polarfist1

    Polarfist1

    Joined:
    Aug 16, 2021
    Posts:
    15
    I have an enemy which uses an AI to follow the player's cylinder position. Once that happens and the enemy goes in contact with the player because of the AI, it is supposed to destroy the player, make the screen red and display text. This was the case but another bug arrived, so I had to turn on Is Kinematic on to stop that other bug.

    Though, this caused the bug I'm talking about right now. Turning off Is Kinematic resolves this bug, but keeps the other, more annoying bug I wont be talking about here on.

    Is there any way to have Is Kinematic on and have the player die on contact? Im putting a few scripts in here for more clarity on the situation.

    Enemy to player contact script:

    Code (CSharp):
    1.     private void OnCollisionEnter(Collision collision)
    2.     {
    3.         if(collision.gameObject.tag == "Player")
    4.         {
    5.             Destroy(collision.gameObject);
    6.         }
    7.     }
    8.  
    9. }
    10.  
    The Cylinder has the ''Player'' tag by the way.

    Death script:

    Code (CSharp):
    1.     void Update()
    2.     {
    3.         if(GameObject.Find("Cylinder") == null)
    4.         {
    5.             text.SetActive(true);
    6.             Destroy(gun);
    7.             DeathFX.SetActive(true);
    8.         }
    9.     }
    10. }
     
  2. Polarfist1

    Polarfist1

    Joined:
    Aug 16, 2021
    Posts:
    15
    Nevermind. I fixed it activating 'all contact pairs'.