- Home /
instantiating "debris" with inherited velocity
hello, so i have this patrol object, it moves from point a to point b. whenever he comes in contact with "Beam", he dies. i also have him instantiate "debris", and it works just fine, the only problem is that i can't get this debris to instantiate with the velocity the patrol had before dying, so it instantiates still, and falls to the ground even though the patrol was going 100mph. so it looks baaaad. this is the code that i currently have:
{
Destroy(this.gameObject);
if (insDebris == true) {
Rigidbody lolwut = Instantiate (Debris, transform.position, transform.parent.rotation) as Rigidbody;
lolwut.GetComponent<Rigidbody> ().velocity = transform.GetComponent<Rigidbody>().velocity;
}
}
i have tried setting the velocity of the patrol on a fixed update, and then use that on the instantiation code, but that doesnt work either, i've also arranged the script so the instantiate line comes first and the destroy line after, but it doesnt work, for some reason the object doesnt die at all, and the debris still has no velocity. any idea of how to accomplish this???
if I can get Addforce to match the patrol's speed, or force, without having to manually hardcode it, i would be happy :)
Answer by TSI25 · May 10, 2016 at 12:52 AM
have you tried waiting to destroy the object until after youve instantiated the debri and set its velocity?
mmm yeah, something like it but it went all funny. i switched the Destroy(This.gameobject) with the instantiate with velocity (literally the same code from the quotation but switched) but it ended up instantiating without velocity (aside from the force applied for having two colliders on the same space) and for some strange reason, the patrol didn't get destroyed...