OnCollisionEnter not working? (178972)

I know this question is asked a lot, and I’ve had this problem before ,but nothing I can find solves my problem. I have a simple script, so that when an object (tree) is hit with an axe, it will drop a piece of wood. However, It doesn’t ever even count as getting hit. The axe is attached to the FPS Controller, and i’m wondering if that’s where my issue stems from. I’ve also tried OnTriggerEnter, doesn’t work. I’ve had the tree with a rigidbody, every piece with a rigid body, the axe and every component with a rigid body, “is trigger” on and off, but nothing works. What should I do? Here’s my script:

// Use this for initialization
void Start () {
Debug.Log("test");
}

// Update is called once per frame
void Update () {
    if(woodcounter >= 15)
        {
        Instantiate(wood, new Vector3(a, 0.5f, a), Quaternion.identity);
        a++;
        woodcounter = 0;
        
    }
}
public GameObject wood;
public float a;
public float woodcounter;
void OnCollsionEnter(Collision other)
{
    Debug.Log("1");
    if(other.gameObject.tag == "axe")
    {
        Debug.Log("2");
        woodcounter++;
    }
}

}

Thanks for the help! This script is attached to the tree, in case that matters. Both the axe and tree are under an empty game object that holds all the child parts, but I don’t think that should matter. And yes, i’ve tried changing the script so that it is on all parts the tree.

Thanks! :slight_smile:

@ShadowNukePie I'm just guessing here but don't spend too much time working on this functionality thinking you will transfer it to Terrain trees because that won't work; search for solutions here on UA if you are planning that.

–

1 Answer

1

void OnCollisionEnter
not

 void OnCollsionEnter

Thanks! It works :D Can't believe i missed something that simple! I wish that would create an error. :/

–

^ This. Thankfully Visual Studio with Unity Tools now has the On... functions with intellisense.

–

I don't see any problems in your code; if u cant use it outside the awake function then there must be something happening when the game start, maybe u change the door obejct name so it cant find it or any thing else ;

–