- Home /
Detach child and add force
Hi, I am trying to pick up an object and then add force to it once it is detached. I am picking it up by making it a child and then detaching it. Can you tell me if it is possible to addforce to the object once it is removed. This is some of the code that I have been experimenting with.
public GameObject player; public float power; public Vector3 way;
void OnTriggerEnter (Collider other) {
if (other.tag == "Throw") {
player = other.gameObject;
other.transform.parent = transform;
}
} void Update(){
if (Input.GetKeyDown(KeyCode.Q)){
player.AddComponent<Rigidbody> ();
GetComponentInChildren<Rigidbody>().AddForce(transform.forward*power);
transform.DetachChildren ();
//
} }
I have looked through previous questions and found similar threads but still cannot get it to work for me. If anyone knows how to add child to an object once it has been detached that would be great.
Thank you!
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Pick up toy and attach to hand 1 Answer
How To Access Children of a Parent Object 1 Answer
How to be sure that the parent's position is the same is the child's position? 0 Answers
Clone wants a Parent (c#)? 1 Answer