Detecting if axe head hit the tree

Hi guys,
So i have a situation: i want to make a script that detects if the box collider on my axe head collided with a tree ( object with tag tree) and if it does hit i want to call a function. How can i detect it? Also im using an axe animation to chop the tree.
Best regards,
Vasco

You want to have a child object of the axe that has a collider and collision script. Note that the axe will collide with things in the world, you can try to build this system using ontrigger for the collider to avoid that.

In the collision script you will want to use either OnCollision or OnTrigger depending on how you try to do it. Research those two functions to figure out how to use them.

Okay i did it. Now i got another situation going on: im trying to instantiate a particle system on the place it hit. I am trying to do

particle = Instantiate (woodChunk);
particle.transform.SetParent(col.gameObject); // col is the collider
particle.Play();

But it doesnt work. Any ideas?

Where is it being instantiated? I don’t see where you set the coordinates for it to show up somewhere. Maybe you instantiated it at 0,0,0 world coordinates?

Well how do i instantiate it exacly where it collided?

you can get the point of collision with col.contacts[0] (or something)
then intantiate has an overload like this: (GameObject, Position, Rotation)

1 Like