- Home /
Collision not detected
Hi all, in a 2d Project the collision evet is not getting fired.
i have a missile gameObject with rigidbody (not kinematic) and 2d box collider
then i have a second gameObject, with rigidbody (kinematic) and a 2d box collider
if i try the collision, i can see the missile, stopping nearby the collider (cause the target is kinematic) if i check the trigger in the target, the missile get through, but the OnTriggerEnter event is not getting fired. The OnTriggerEvent is located in a script in the target gameObject
void OnTriggerEnter(Collider other) {
Debug.Log ("Collide");
if (other.tag == "Laser") {
Debug.Log("Hit by a Laser");
}
}
what am i doing wrong?
Answer by Zote908 · Jan 17, 2020 at 05:12 PM
I can tell you only some alternatives such as OnTriggerEnter(Collider other) should be OnTriggerEnter2D(Collision2D other) { } Or instead of if (other.tag == "Laser") { } I'd use if (other.gameObject.CompareTag("Laser")) { }
I know it's a common thing but i'm a learner so sorry if it doesn't work
Answer by logicandchaos · Jan 17, 2020 at 05:23 PM
Yes it needs to be OnTriggerEnter2D and use Compare instead of ==, also I think other.tag should be other.gameObject.tag. The other thing to check is to make sure your objects are all tagged correctly. You can put a debug.log(other.gameObject.tag) to check to see the tags that are colliding.
Answer by PietroCarta · Jan 17, 2020 at 05:34 PM
Appreciate your answers guys but the question is from 2014!
Your answer
Follow this Question
Related Questions
Collision Detection without a RigidBody 2 Answers
Collision problem in C# 4 Answers
OnTrigger event when colliders are already touching eachother 1 Answer
2 objects collide, need to destroy one 2 Answers