So I am a beginning coder who has been writing in Javascript up until this point, but what I am doing now is creating a short script that disables the ragdoll effect after the enemy has died. I am using a custom method that is a part of the asset pack we are using - Paragon AI (I think now called Tactical Shooter AI or something).
I have followed the instructions of the author who told me how I could go about disabling the effect via turning off the colliders of the object and setting the rigidbody to kinematic which works; however the enemy just freezes as soon as they die so they are not dropping to the ground. So I figure I need a short timer that runs through before the rest of the code, so that the bodies have time to hit the ground before the ragdolls are disabled.
Here’s my code.
using UnityEngine;
using System.Collections;
public class disableRagdoll : MonoBehaviour {
Collider[] rigColliders;
Rigidbody[] rigRigidbodies;
void Start (){
rigColliders = GetComponentsInChildren<Collider>();
rigRigidbodies = GetComponentsInChildren<Rigidbody>();
}
public void OnAIDeath()
{
//wait 2-3 seconds.
foreach (Collider col in rigColliders){
col.enabled = false;
}
foreach (Rigidbody rb in rigRigidbodies){
rb.isKinematic = true;
}
}
}
I have commented where I think the timer should go, is anyone able to help me out?