Search code examples
unity-game-enginecollision-detectionrigid-bodiescollider

Unity OnCollisionEnter function not registering


I am not able to register my OnCollisionEnter(); I have copied the function from a previous Unity program that works and replicated everything. The collision between the FPSController should be lowering the TreeHealth.

enter image description here enter image description here

    void OnCollisionEnter(Collision collision)
    {
        print("Colision");
        if (collision.gameObject.tag == "TreeTag")
        {
            treeScript = collision.gameObject.GetComponent<TreeFall>();
            treeScript.treeHealth--;
        }
    }

Solution

  • Did you try to use OnControllerColliderHit? I think you have to use this method instead of OnCollisionEnter if you move the character with the CharacterController Component.