Enabling "isKinematic" on Rigidbodies freezes script momentarily (video included)

TL;DR: Video explanation here http://youtu.be/WJZ6_TOdu3A

Hi All,

I am currently in the process of developing a PoC for a Zombie game. I have a zombie model who is rigged/animated, and I’ve made a Ragdoll for him as well. The Rigidbody components got attached on all of the proper places. When I turn “isKinematic” on and animation off, the zombie falls to the ground as I wanted him to.

The reason I am doing this is to avoid a die animation (which wasn’t included with the model). The goal is that, when the zombies die, they’ll simply go limp and fly away with the force of the bullet (obvs not very far, but I do want to see some Zombie carnage).

Here is the script that I am using to accomplish this at the moment:

using UnityEngine;
using System.Collections;

public class Zombie : RTSUnit {

	public float kill_after = 5;
	private float kill_counter = 0;
	private bool dead = false;
	private Rigidbody[] rigidBodies;

	// Use this for initialization
	void Start () {
		rigidBodies = GetComponentsInChildren<Rigidbody>();
		foreach(Rigidbody r in rigidBodies) {
			r.isKinematic = true;
		}
	}
	
	// Update is called once per frame
	void Update () {
		if(kill_counter > kill_after  !dead) {
			Debug.Log("STARTING AT " + System.DateTime.Now);
			dead = true;
			for(int i=0; i<rigidBodies.Length; i++) {
				rigidBodies[i].isKinematic = false;
				rigidBodies[i].useGravity = true;
			}
			Debug.Log("FINISHED AT " + System.DateTime.Now);
		} else if(!dead) {
			kill_counter += Time.deltaTime;
		}
	}
}

Just a wild guess but maybe when you turn isKinematic off on the rigidbodies, they will immediately collide and conflict with the zombie’s Character Controller. You could just put the rigidbodies on another layer and turn collisions off between the two layers in the Physics Settings to rule that out.

I removed the entire CharacterController component from the top-level Zombie GameObject, but to no avail.

Color me stupid.

I have an Animation component attached to the Zombie and it was set to Play Automatically.

But, you might be wondering, where is the Animation stuff in the script? Nowhere. Because the animation was playing once (and was just under 5 seconds long) and then stopping. Then, shortly thereafter, the zombie would go limp.

I have fixed him and now the effect is quite awesome. I added a simulated bullet-force to his head, just for kicks.

I’ll put up a video soon.