I’ve been trying to get the OnCollisionEnter function to work with characters. It works fine, unless the character is Instantiated. I’ve tried this with as simple a setup as i could; i made a prefab with a CharacterController, and put this script on, then put it in a scene, threw some rigidbodies at it, and it worked. When the instantiated one came up though, it wouldn’t work at all. It didn’t print the time either, so I think that OnCollisionEnter isn’t being called at all.
I wouldn’t be surprised if i’ve overlooked something obvious, but I can’t seem to figure out what.
// newThing is the same object; just instantiates another one of itself
var newThing : GameObject;
var health = 3;
function OnCollisionEnter (collision : Collision) {
print(Time.time);
health -= 1;
if (health <= 0) {
Die();
}
}
function Die () {
Instantiate(newThing, transform.position + Vector3.right*2, transform.rotation);
Destroy(gameObject);
}