Hi All!
I want some NPC’s to turn into ragdolls when colliding with the player. For some reason I can’t seem to give the instantiated ragdoll the same velocity / force, as the NPC it instantiated from, and it just stops and slides to the ground… Did I script it wrong? Or did I take a whole wrong aproach to giving the Ragdoll velocity when instantiated?
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag == "Player"){
ragdoll = Instantiate(ragdoll, transform.position, transform.rotation);
colliders = ragdoll.GetComponentsInChildren(Collider);
for (var col : Collider in colliders)
{
Physics.IgnoreCollision(col, collider);
}
rigidbodies = ragdoll.GetComponentsInChildren(Rigidbody);
for (var child : Rigidbody in rigidbodies)
{
child.rigidbody.velocity = rigidbody.velocity;
child.angularVelocity = rigidbody.angularVelocity;
//child.rigidbody.AddForce (Vector3.up * 1000);
}
Destroy(gameObject);
}
}
the rigidboy.AddForce at the end is there for test purposes, and works in the current setup. Setting the child’s velocities doesn’t seem to work at all though… If been searching for a while now, since I’m guessing it’s a common problem, but I can’t seem to find anything usefull on the subject…
Thanks in advance!! I’ve been struggling with this for days, any help apriciated!