parent object to collider

I have made a script, which fires an arrow, and the velocity increases the longer you hold the mouse button.
Now I want my arrow to be parented to whichever object it hits, so that it not only stops when it hits something, but also sticks to the enemy’s head for example. My logic says it shouldn’t be very hard :stuck_out_tongue: But yet I find it quite impossible

Thanks

EDIT: I have tried many different ways now, can’t figure it out

Simple enough (writing this off the cuff in C#, so pardon any glaring API errors)

void OnCollisionEnter(Collision targetHead)
{
    //  also code in removing any forces etc
    //  on the arrow ala setting it to a dormant
    //  state, and use the Collision exposed by
    //  this function to make it the new parent

    transform.parent = targetHead.transform;
}

Should work…I’m full of disclaimers tho :slight_smile:

If you use triggers instead of colliders it is slightly different in that you get a handle on a Collider instance, not Collision, but the parenting will work the same.

void OnTriggerEnter(Collider targetHead)

That worked out perfectly! Now I can shoot Tom Hanks in the head :smile: I usually work in JS but it wasn’t so hard to figure out.

Actually I stumbled over that method a while ago, but stuck in a moment of aggression from syntaxes and shit :stuck_out_tongue:

Thanks for the solution :slight_smile:

You mean in the game, right? That’s not just how you celebrate solving a problem? :wink:

Oh… Too late pal :stuck_out_tongue: