- Home /
Child not working with triggerEnter
I'm working on a script for a held sword item. The sword item has a trigger box that is intended to trigger when coliding with an enemy, dealing damage to it. The problem is that for whatever reason the trigger is just... not triggering. void OnTriggerEnter2D(Collider2D coll) { Debug.Log ("Hit"); if (coll.gameObject.tag == "Enemy") coll.gameObject.SendMessage ("hit", damage); Debug.Log ("Hit"); }
No errors apear, and the dubugs don't show up. Both the enemy and sword have hit boxes, as well as rigidbodies. Additionaly the boxcollider's are both 2d, as well as the rigid bodies. The sword's collider is labeled trigger, and the enemy one is not trigger. The sword is kinisthetic. So I have no clue what could possibly be wrong. Any help is apreciated!
Answer by upasnavig90 · Feb 16, 2018 at 06:41 AM
Hey, please check if either of rigidbodies have "isKinematic" enabled or not, try disabling the option.
Answer by ransomink · Feb 16, 2018 at 02:23 PM
First, make sure the enemy has the "Enemy" tag. Also, A Kinematic Rigidbody 2d cannot collide with another; at least one of the rigidbodies must be set to Dynamic. Since your sword is Kinematic, your enemy must be Dynamic..
Ok so I've found the problem but now I'm even more confused. Yes the enemy has the propor tag, and yes apearantly both are $$anonymous$$inematic. The reason being though is that any time I change ones $$anonymous$$iematic the both change automatically. Like If I change the sword to kinesmatic it changes the enemy as well, and vice versa. So now I have a completly different problem and I'm even more confused, any ideas? And thanks for the help so far!
That doesn't make sense. I'd delete their rigid bodies and place a new one. At least one of them has to be a dynamic rigid body...
Your answer