- Home /
Resume movement of instanced object relative to the original after instantiation.
I'm working on some mechanism where after I throw an object, at a certain impact force break the object. My only problem is after the cracked version of the moving original one, the direction/movement of the original one gets lost, and leaving the instance just stop on instantiation then going to pieces, now that's just not realistic. As an example watch a hl2 demo of its physics on throwing.
Answer by StephenALEGROS · Dec 27, 2018 at 01:33 PM
Found the solution after a some trial and error.
I found out using a GetComponentsInChildren and using you said @ray2yar. Thanks.
Answer by ray2yar · Dec 27, 2018 at 01:36 AM
You could give the original object's velocity to your instantiated objects. Something like this:
void OnImpact()
{
GameObject myCracked = Instantiate(Cracked, transform.position, Quaternion.identity) as GameObject;
myCracked.GetComponent<Rigidbody>().velocity = GetComponent<Rigidbody>().velocity;
}
@ray2yar Good idea, but that cannot be for the instantiated object is just an empty, to parent children that is then have the rigidbodies. I tried it. Is there anyway to access all of the rigidbodies of its children?
Attach a script to the empty object with a public Vector3 variable. Then something like this:
myCracked.GetComponent<SomeScript>().SomeVariable = GetComponent<Rigidbody>().velocity;
Then when you attach the children have them access this variable and get the inherited velocity.