Projectile that becomes child (like a arrow that stucks to objects)

I haven’t posted in this forum before, but I’ll try to make myself understood (sry for my grammar, but I’m a swe youknow)
Anyway

I’m instantiating a arrow from a crossbow, and my arrowscript is currently

But it does not work as it should. I want it to become the child of the object it hits (so if the object moves, the arrow does it too), and then if it gets unstuck, it should become the child of “cloneLibrary” (an empty object to keep my inspector clean).

It would be really nice if someone could help me, I’m a beginner at programming :frowning:

I’m pretty sure its OnCollisionEnter OnCollisionExit not OnColliderEnter and OnColliderExit…

Often people mix up default function names, so Unity will not recognise that function unless you ask it to…

Try this:

var bulletSpeed : float = 100;
var hit : boolean = false;
var gotSpeed : boolean = false;
var cloneLibrary : GameObject;

function FixedUpdate (){
     if (!gotSpeed){
          _____rigidbody.AddRelativeForce (Vector3.forward * bulletSpeed);
          _____gotSpeed = true;
          _____rigidbody.constraints = RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
     }
}


function OnCollisionEnter (other : Collider){
     transform.parent = other.gameObject.transform;
     rigidbody.constraints = RigidbodyConstraints.FreezeAll;
     rigidbody.useGravity = false;
}

function OnCollisionExit (other : Collider){
     transform.parent = cloneLibrary.transform;
     rigidbody.constraints = RigidbodyConstraints.None;
     rigidbody.useGravity = true;
}