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)

There is a pretty good thread about character controller collision [here][1] In [This Link][2] it shows the use of OnControllerColliderHit but it may have some limitations that are discussed in the first link. [1]: http://forum.unity3d.com/threads/96177-Character-controller-Collision-Detection [2]: http://answers.unity3d.com/questions/199010/how-to-get-collisions-on-character-controller.html

This may be an edge case, as the inspector for the .asset does not have any options (ie. the readable option that is usually on obj, fbx assets etc) Although I've just realised the OP doesn't fit what I was trying to do (googling for) anyway :)

4 Answers

4

Both GameObjects needs to have a collider component (that is not set as a triggers).

either the player or the object this code is attached to doesn’t have a collider/rigidbody

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

I had this problem and turning off kinematics worked out for me. :smiley: