- Home /
add relative force to child after detach.children
hey, how do i detach a child and add a reletive force at the same time from a script on the parent?
plz JAVA :P
Answer by Jesse Anders · Dec 24, 2010 at 04:20 AM
It's actually Java, not JAVA, and it's actually JavaScript, not Java. (And technically, it's actually UnityScript, not 'real' JavaScript ;)
The language thing might not seem important, but there's enough confusion about languages flying around as is, so I generally try to provide clarification when it seems appropriate.
Although I'd have to check to be sure, I think to detach a child you can simply write:
child.transform.parent = null;
Assuming 'child' references a child game object.
If you want to apply an 'all at once' force at the moment the object is detached, you'll probably want to use the 'impulse' force mode, e.g.:
child.rigidbody.AddRelativeForce(force, ForceMode.Impulse);
Ill keep that in $$anonymous$$d :) i dont hink i worded this right i am instantiating an object from its parent, and the parent only has one child, but i dont know that childs name, what should i do?
I'm not sure what you mean exactly, but you can access the children of a game object by iterating over its transform (see the documentation on the Transform class for details).
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
How to control parenting in multiple functions 1 Answer
Detach a child that has children 1 Answer
Can I detach child objects from their parent? 2 Answers
Removing specific child objects 1 Answer