- Home /
Adding a rigidbody to an array?
Iv got a model which is skinned and has bones in it, what i want to do is when the health reaches 0 I want all the bones to add a rigidbody onto them but i don't know how i would go about doing this in C#?
You should look at using Ragdoll ins$$anonymous$$d : http://docs.unity3d.com/Documentation/Components/wizard-RagdollWizard.html
first video I found : http://www.youtube.com/watch?v=XSQATmz5Yn4
I learned ragdoll from the 3D Buzz tutorial. Click the below link, scroll down to : Section 4 - Integrating Animated $$anonymous$$aya Characters : 30 - Setup Ragdoll (also videos 31 and 32)
http://www.3dbuzz.com/vbforum/content.php?212
as you are in C#, you should follow along, to see how they replace their character with the ragdoll, recursively match all the limbs to the correct position and rotation, then hide your character and show the ragdoll. ($$anonymous$$iraSensei has shown how this can be done in his answer)
this is the model isn't a standard character its actually an animal which would be rather hard to put into a ragdoll i would imagine.
No problem, just thought I'd put it out there in-case you wern't aware of it =]
Although it would be interesting to see what the Ragdoll wizard does to an animal shape ! $$anonymous$$y guess is that it would work quite well if you assigned the associated limbs correctly. What the ragdoll wizard does is add rigidbodys and colliders to certain parts of the skeleton, kinda what you're after? You should make a ragdoll just for fun and see what it does. It takes 1 $$anonymous$$ and makes a new prefab so your model isn't changed in any way =]
Answer by KiraSensei · Sep 04, 2012 at 03:45 PM
Did you already get an array of your bones ?
If not, you should start with this. Create an array that you fill with all the bones in the inspector, then loop on it and add the component !
for (int i=0; i<bones.length; i++)
{
bones[i].AddComponent("Rigidbody");
}
Have a look to : http://answers.unity3d.com/questions/41528/find-a-child-with-a-name-how-to.html
This may help you...
well also what i want to do is add the bone objects throught script eg finding them by tag or by name
thank you very much just one more thing i have attached some colliders on my model and if it's health reaches 0 then the colliders switch from triggers to colliders but the model still falls through the floor and i have all the floor with colliders on, any thoughts?
What is exactly the confiduration ? The very important thing is that your floor should have a mesh collider, but your character should not. It can have a box collider, sphere ... but no mesh collider. 2 $$anonymous$$eshes colliders can work together only of one of them is convex (a check box in the inspector), but in your case it may not be the case ...
Just try an other collider on your player and tell me !
ahh it works now it was just becasue i had 1 collider on the spine of the model and the rest of the bones didnt have colliders but they had rigidbodies so they went throught the ground, iv attached all colliders to all bones and now i have to find a way of restricting the bones to go so far becasue when the model dies it streches in all directions but thanks for the help :)
No problem :)
Colliders were not easy for me too. Don't forget to accept the answer please :)