Hi All!
I’m trying to make ragdolls fly extra nice when I hit them with a vehicle, using the AddExplosionForce function.
With the help of two members here we came up with two scripts, but neither seems to have any effect on the ragdolls…
Both the scripts are attached to the car itself, wich runs on the scripts from the car tutorial. The ragdolls are created with the Ragdoll wizzard, and for testing purposes, I use a standard Sphere object, with a rigidbody attached.
EDIT
Here’s a test project with the same setup as we use. The script we’re using is the DarknessBlast.JS, attached to the car. You can see that when hitting the cubes, with the spheres selected as “Ragdoll” in the DarknessBlast script, the spheres seem to be impacted by the AddExplosionForce function just fine… When you select the SoldierRagdoll as “ragdoll” the AddExplosionForce doesn’t work at all, not with or without a rigidbody to the Soldierragdoll’s parent gameobject…
First Script, by @ChrisD:
var ragdoll: GameObject;
var power : float;
var radius : float;
var upModifier : float;
var moveSpeed = 5;
function OnCollisionEnter (collision : Collision) {
print("collision");
var colGameObj = collision.gameObject;
if (colGameObj.tag == "Enemy"){
Debug.Log("Enemy Success");
var newRagdoll : GameObject = Instantiate(ragdoll,
colGameObj.transform.position,
colGameObj.transform.rotation);
for (var c in collision.contacts){
newRagdoll.rigidbody.AddExplosionForce(power,
c.point, radius,
upModifier);
}
Destroy(collision.gameObject);
}
}
This script instantiates fine, as long as I add a rigidbody to the parent Ragdoll object. If I don’t it just keeps on spawning ragdolls.
I have tried cranking up the power to a 100.000, but the AddExplosionForce doesn’t seem to work, not on the ragdolls, and not on the test-sphere…
The 2nd Script, by @ConfinedDarkness:
var ragdoll : Transform;
var power : float;
var radius : float;
var upModifier : float;
private var canContinue : boolean = true;
function OnCollisionEnter (collision : Collision) {
for(var contact in collision.contacts) {
if(canContinue) {
if(contact.otherCollider.rigidbody) {
if(contact.otherCollider.gameObject.tag == "Enemy") {
var newRagdoll : Transform = Instantiate(ragdoll, contact.otherCollider.transform.position, contact.otherCollider.transform.rotation);
Destroy(contact.otherCollider.gameObject);
newRagdoll.rigidbody.AddExplosionForce(power, transform.position, radius, upModifier);
canContinue = false;
}
}
}
}
canContinue = true;
}
This script does seem to work with the test-spheres, but also has no explosive effect on the ragdolls, with and without a rigidbody attached to the parent ragdoll object.
Anybody any idea on why one or both of the scripts doesn’t work on raggdolls?
Thanks in advance!