football script

Hi, I just tested that function where the ball sees the player as it's parent. I don't understand much about root and parent in unity javascript. Do you know how to unparent the ball and have it shoot in the direction the player is facing?

Thanks,

1 Answer

1

name your object “football”, drop it into a parent (the player object), and put this in the parent objects script.

		//lookup the football by child's name
		GameObject fb = transform.Find ("football").gameObject;

		// unparent the football
		fb.transform.parent = null;

		//add a rigidbody;
		Rigidbody r = fb.AddComponent<Rigidbody> ();

		//add forse to the football's rigidbody in a direction
		r.AddForce(transform.forward*50);