Right now i have an enemy with a sword that attacks the player and for some reason the sword obviously goes into the player collider but randomly doesnt detect the collision. Like i said its completely random when it does or doesnt collide even though its literally doing the exact same thing over and over. Heres the code for my OnTriggerStay function
public class jumpdetect : MonoBehaviour {
private bool isjumping = false;
void OnCollisionStay(Collision theCollision){
foreach (ContactPoint contact in theCollision.contacts) {
if(contact.normal.y > 0.9f){
isjumping = false;
break;
}
}
}
void OnTriggerStay (Collider c){
Debug.Log (c.tag);
if(c.tag == "Finish" & transform.FindChild("Weapon").GetComponent<Animator>().GetBool("Attack") == true & transform.parent.GetComponent<cubeenemy>().alreadyhit == false){
transform.parent.GetComponent<cubeenemy>().alreadyhit = true;
GameObject.Find ("Player").transform.GetComponent<playersetup>().currenthealth = GameObject.Find ("Player").transform.GetComponent<playersetup>().currenthealth - transform.parent.GetComponent<cubeenemy>().damage;
if (GameObject.Find ("Player").transform.GetComponent<playersetup> ().currenthealth <= 0 & GameObject.Find ("Player").transform.GetComponent<GaryCharacterController> ().isplaying == true) {
GameObject.Find ("Player").transform.GetComponent<GaryCharacterController> ().isplaying = false;
GameObject.Find ("Player").transform.GetComponent<GUIscript> ().gameover();
}
}
if(c.tag == "jump" & isjumping == false){
rigidbody.velocity = new Vector3(rigidbody.velocity.x, 5, 0);
isjumping = true;
}
if (c.tag == "weapon" & GameObject.Find ("Player").transform.FindChild ("Weapon").GetComponent<Animator> ().GetBool ("Attack") == true & GameObject.Find ("Player").transform.GetComponent<GaryCharacterController>().alreadyhit == false) {
transform.parent.GetComponent<cubeenemy> ().takedamage ();
GameObject.Find ("Player").transform.GetComponent<GaryCharacterController>().alreadyhit = true;
}
}
}
I am printing out the c.tag as you can see but it sometimes prints out and sometimes doesnt. Heres a picture of an example of when it decides not to detect the collision [19402-screen+shot+2013-12-15+at+10.57.05+pm.png|19402]
And heres another picture showing the information of the players box collider
[19403-screen+shot+2013-12-15+at+10.57.22+pm.png|19403]
Sorry if the code is really difficult to understand since its completely out of context but if you have any ideas as to why this occurs i would appreciate the help. Thanks!