Collision between two sphere game object

In my game scenario , i have two sphere game object. In that i have one sphere game object is on statis position and other sphere game object is used as bullet. For that i have created prefab of sphere game object. And i have put empty game object in my 2D scene and instantiate my bullet prefabe on that empty game object position.

Now when i shoot bullet i want to detect collision. I have tried so many methods but none of them works for me.

My code:

function Update ()
    var spawnPoint : GameObject = GameObject.Find("Bullet");
		 if(spawnPoint != null)
			  var hit  : RaycastHit ;
	          var ray : Ray  = Camera .main .ScreenPointToRay (Input .mousePosition );
		      if(Physics.Raycast (ray, hit))
		      		 shootProjectile = Instantiate(bulletSphere, spawnPoint.transform.position,spawnPoint.transform.rotation);
				     shootProjectile.rigidbody.useGravity = false;
				     var tempx = hit.transform.position.x;
				     var tempy  = hit.transform.position.y;
				     shootProjectile.rigidbody.AddForce (shootProjectile.transform.TransformDirection(new Vector3(tempx,tempy,0) * 8000 * Time.deltaTime));		
				     //if(hit.collider.gameObject.tag == "Enemy")
//				     {
//				     	Destroy(hit.collider.gameObject);
//				     }		     	

Method i have tried :

OnControllerColliderHit (hit : ControllerColliderHit)

OnCollisionEnter(other : Collision )

Which collision matrix do i need to use?

please please help me to solve my this problem. Thanks in advance. :frowning:

I’m not sure what you have your mass set at for your bullets, but if it is 2.0 or below, a force of 8000 is going to sent it bulleting (pun intended) out of the gun. The problem is that for the bullet to collide, the bullet and the collider must be at the same place. With something moving so fast, it is highly likely that between one collision test and the next it will start out in front of the object and then be behind the object without ever touching the collider.

A couple things you can try:

  • Cut the force. If you have a mass of 1, try cutting the force you apply to 4000, or even 2000.
  • Change the collision detection on the rigidbody to Continuous or Continuous Dynamic.

And you want OnCollisionEnter()