Arrow Stab into ground and stay(script)

Hello :slight_smile: I need help…

this is the code i am currently using

CODE#

private var cam : follow_transform;

function Start()
{
	rigidbody.useGravity = false;
}

function Update () 
{
	if(cam.fire)
	{
		FireArrow();
	}
}

function OnCollisionEnter(info : Collision) 
{	
	if(info.gameObject.tag == "ground")   //ground is the base 
	{
		transform.rigidbody.isKinematic = true;
		gameObject.transform.parent = info.gameObject;
		DestroyAfteryield(2);
	}
}

function FireArrow()
{
	rigidbody.useGravity = true;
	rigidbody.AddForce(-transform.forward * cam.fireforce * 110,ForceMode.Force);
}


function DestroyAfteryield(time : float)
{
	yield WaitForSeconds(time);
	Destroy(gameObject);
}

what i actually want is that when the arrow hits the ground it should actually stick there(just like a knife is stabbed)everything seems to work fine the arrow sticks to the ground but the moment it collides with the ground it gives an error(Cannot cast from source type to destination type in the following line(gameObject.transform.parent = info.gameObject;))and the arrow doesn’t get destroyed as it should be according to the DestroyAfterYield function.

can anyone help me out with this
thanks in advance

I think you need to parent to the ‘transform’ of the gameObject, not the gameobject itself.

try:

gameObject.transform.parent = info.gameObject.transform;

(not tested)

not sure on the destroy thing. Maybe that exception was causing that function to quit at that point, therfore not running the destroy. Put a print in the destroy function, see if it gets called.

thanks everyone for there help and support. instead of figuring out how to maintain scale… i was more concerned about the errors…and was not using transform instead of game object anyways thanks all