I was wondering what a script would be to detach the children and add a rigidbody and appropriate collider these gameobjects:
I guess something like this.
var spheres : GameObject[];
var cylinders : GameObject[];
// choose a sphere or cylinder somehow, put it in var child : GameObject
child.transform.parent = null;
if ( wasChosenFromSpheres ) {
child.AddComponent( "Sphere Collider" );
else if ( wasChosenFromCylinders )
child.AddComponent( "Mesh Collider" );
child.AddComponent(Rigidbody);
I can’t test right now so “Mesh Collider” and “Sphere Collider” might not be the actual names you need.
how could i get this to work?
the script doesnt exactly work, how could i get it to work?
Why do you want to wait until the detachment to add the collider and the rigidbody? Do you want them to phase through things until they are detached?
what happens if i have the colliders if the snowman shakes a lot, and if i have the rigidbodies, the parts start flying around. the snowman is the enemy, but only the snowman base, labeled snowman, can have those things or else the stuff up top happens
Try having the colliders and rigidbodies on all of the children object, but set the rigidbody to is kinematic, then when the snowman dies, roll through all the children in the transform with rigidbody components, and set is kinematic to false?
Move the script’s pieces where they belong in your script. I assume you’ll want the variables declared outside of functions so they’ll be editable in the inspector, and you’ll want the parts that detach and add rigidbody to be in the function you’ve already written to detach and add rigidbody.
You could parent the body parts you want to a empty GameObject, then when you tell it to die, roll through the GameObject’s Children detach them and the add a rigid body to them. I wouldn’t necessarily make each part kinematic, just the empty GameObject.