- Home /
Unity wont detect when my objects collide?
Hi Guys, im having some trouble with my Unity Collision code and i really cant tell whats going wrong.
void OnCollisionEnter(Collision target){
if (target.gameObject.tag == "Player"){
print ("bang");
if(drilling == true){
Destroy(gameObject);
}
}
}
I added the print statement to help detect where my code was going wrong but even that didn't appear. I am trying to make it that my character will destroy the the object when they touch it (and are drilling). but I also want the player to not just pass through the object (like with trigger events)
Try this and see if you get a print out.
void OnCollisionEnter(Collision target){
print("Collision Detected");
if (target.gameObject.tag == "Player"){
print ("bang");
if(drilling == true){
Destroy(gameObject);
}
}
}
This should let you see if you are even detecting a collision.
If you are getting the first message but not the second message then you aren't colliding with a gameObject that has a tag named Player.
If you are not getting the first message then you haven't setup the collider correctly.
Look Here for some help with setting up colliders
Answer by alexanderbrevig · Apr 18, 2013 at 06:12 PM
Both GameObjects needs to have a collider component (that is not set as a triggers).
Answer by sparkzbarca · Apr 18, 2013 at 05:12 PM
either the player or the object this code is attached to doesn't have a collider/rigidbody
Answer by sethrow · Apr 24, 2013 at 08:36 AM
At the moment my character has the character controller and rigidbody attached, and my objects have box collider and rigidbody, none are set to triggers. Unity will detect when the objects collide with each other but for some reason they wont when i have the character controller instead of a box collider
Answer by carlegos · Mar 22, 2019 at 06:46 AM
I had this problem and turning off kinematics worked out for me. :D
Your answer
