Hi everyone i use this code for enemy of my game but i have a problem in addforceing to enemy ragdoll : This code add no force to my ragdoll !!!
function Detonate () {
// Destroy ourselves
// Play a dying audio clip
if (dieSound){
AudioSource.PlayClipAtPoint(dieSound, transform.position);
}
// Replace ourselves with the dead body
if (deadReplacement) {
var dead : Transform = Instantiate(deadReplacement, transform.position, transform.rotation);
// Copy position rotation from the old hierarchy into the dead replacement
CopyTransformsRecurse(transform, dead);
DelAndForce (dead);
}
}
function ApplyDamage(damage:int){
Total_blood-=damage;
if (Total_blood<=0 deadable_flag){
deadable_flag=false;
Destroy(gameObject);
print(Total_blood);
Detonate();
}
else{
animation.CrossFade("Idle");
print("enemy in Idle animation");
enemy.GetComponent("Seeker").StartPath(enemy.transform.position,enemy.transform.position);
}
}
static function CopyTransformsRecurse (src : Transform, dst : Transform) {
dst.position = src.position;
dst.rotation = src.rotation;
for (var child : Transform in dst) {
// Match the transform with the same name
var curSrc = src.Find(child.name);
if (curSrc)
CopyTransformsRecurse(curSrc, child);
}
}
function AddForcetoRagdoll(){
var hit : RaycastHit;
var directionl = guncammera.TransformDirection(Vector3(0,0,1));
if (Physics.Raycast (guncammera.position, directionl, hit)) {
print(hit.rigidbody);
// Apply a force to the rigidbody we hit information
if (hit.rigidbody){
hit.rigidbody.AddForceAtPosition(5000 * direction, hit.point);
print(hit.rigidbody);
}
// Place the particle system for spawing out of place where we hit the surface!
// And spawn a couple of particles
}
}
How can i fix it ?