I am having such a hard time with this and I cant figure out why. I have two game objects: “player” and an enemy called “skeleSword”. Both have rigid bodies and colliders. Player is using the FPS controller. “skelesword” has two child objects containing colliders: one on the weapon and one on the head. I scripted the weapon collider to destroy “player” on trigger enter. I scripted the Head collider to destroy “skelesword” on trigger enter. Then I made “skelesword” a prefab that spawns at random intervals. The problem I’m having is this: the body collider doesnt always detect a collision and the player falls through it.
Code:
Head Collider:
private GameObject skeleSword;
void Start () {
skeleSword = GameObject.FindWithTag("skeleSword");
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player") {
Destroy (skeleSword);
Debug.Log ("enter");
}
}
Weapon Collider:
private GameObject hank;
void Start () {
hank = GameObject.FindWithTag("Player");
}
void OnTriggerEnter(Collider other){
if (other.gameObject.tag == "Player" ) {
Destroy (hank);
Debug.Log ("enter");
}
}
Here are some images from the project:
Weapon Collider is the exact same as the Head collider, but with the weapon collider script.