How to make gore physics effect like cut monster’s part?
by weapon or spell?
How to make gore physics effect like cut monster’s part?
by weapon or spell?
you can probably destroy the monster when it dies and then instantiate some gory parts (though there must be a cheaper (performance wise) way of doing it.
I tried fps tutorial’s Ragdoll effect.
But when I change it’s joint’s break force from infinite to 1, it just looks like longer rubber. Skin mesh are just stretched.
They don’t teared apart.
Then how can make them apart?
Replacing them to aparted prefab is only way?
putting up
If you don’t want a bunch of prefabs, you can dynamically cut ragdolls using this code below -
(This is written freehand; I haven’t run it in Unity, but it’s very close to my actual code so it shouldn’t be too hard to get working)
partToRemove : String = "Arm.Right" // or whatever
ragdoll = CreateRagdoll();
// Get all the parts
ragdollParts = ragdoll.GetComponentsInChildren(Transform);
for ( var part : Transform in ragdollParts ) {
// Search for the part that indicates where we cut
if ( part.name == partToRemove ) {
// scale to 'zero' all children of that part
// effectively they become invisible
for ( var remove : Transform in part.GetComponentsInChildren(Transform) ) {
remove.localScale = Vector3.one * .001; // Not 0, or Quaternions can start to complain about zero vectors and that's just no fun
}
}
}
// Now we're going to make the removed limb
// Make a second ragdoll
ragdoll2 = CreateRagdoll();
// get its parts
ragdollParts = ragdoll2.GetComponentsInChildren(Transform);
// keep a list of parts that should stay visible
var partsToKeep : Array = new Array();
// we're going to need a new 'base part'
// my characters usually have Spine1 as their base
// if Spine1 gets scaled to 'zero' while it's still the super-parent, everything goes invisible
// which is what we don't want.
var newParentPart : Transform;
// First we find that part that will be the new parent
// (the part that's getting cut off)
for ( part : Transform in ragdollParts ) {
if ( part.name == partToRemove ) {
newParentPart = part;
for ( var keep : Transform in part.GetComponentsInChildren(Transform) ) {
partsToKeep.Add( keep )
}
}
}
// Set its parent to null
// You may want to set this to something else
// for example, a ragdoll controller or arrow.
newParentPart.parent = null;
// Now let's get rid of those parts that aren't in this limb
for ( part in ragdollParts ) {
var keepThisPart : boolean = false;
// if this part isn't in our list of good parts
for ( query in partsToKeep ) {
if ( query == part ) keepThisPart = true;
}
// we'll throw it out
// we can't destroy it or the skinned mesh renderer
// will become extremely upset with us
if ( !keepThisPart ) {
// so set its parent to the base part
// and scale it to 'zero' so it's 'invisible'
part.parent = newParentPart;
part.position = newParentPart.position * .99 + part.position * .01; // don't put them right on top of each other or quaternions again
part.localScale = Vector3.one * .001;
}
}
You may try experimenting with removing rigidbodies and colliders from removed ragdoll pieces as well. My actual code has lots of extra tidbits due to how I’ve created my ragdolls, but this should be good generic fodder.
This can cause some parts of the ragdoll to scale poorly (for example, the stomach area of mine becomes a tiny little circle instead of the large mass it should be). I haven’t gotten around to fixing that yet, but I imagine having some prefabs to spawn on top of the problem areas will be a decent solution and should allow you to create appropriate-looking stumps.
This code is very slow, and even though it only runs once in a while it can’t hurt to optimize it. Trying to create two ragdolls in one update causes very noticeable lag. If there enough ragdoll bits, just one can do it.
Also, the two “GetComponentsInChildren” calls that I use will return ALL transforms, including the Mesh renderer. If ALL the bones of your ragdoll are rigidbodies, you may want to use GetComponentsInChildren(Rigidbody) instead of (Transform).
Very thanks for reply.
I have look through the script. But this can be useful cutting part of ragdoll.
Then, how about crushing the stone or ice statue effect?
And glass shattering effect?
They must be affected by physics force from other source like weapon or spell’s.