- Home /
Question by
helioraanswer · Apr 17, 2011 at 01:52 PM ·
rootfootballunparenting
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,
Comment
Answer by toddisarockstar · Jul 23, 2017 at 11:26 PM
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);