Can't detect collision between imported model and instaniated object.

Hi,

This is my first question here. I usually solve all my problems with google, the manual or this forum. But this time I seems to have no other choice then to ask you guys!

I’m making a first person zombie survival (everyone has to start somewhere, right?). Now I want the zombies to loose health when the player throws a rock at them. Everything works like charm except I can’t get Unity to detect the collision between the instantiated rock and the Zombie. Some info before the code:

  • The zombies uses character controller to get around

  • I use these zombies

  • The rocks bounces of the mesh, so I can visually see that the zombies indeed are getting hit by the rocks.

  • The instantiated rocks are tagged correctly.

  • If I create a simple cube with the same scrips as the zombies, unity detects the hit on the box.

  • I turned of the animation on the Zombie and still no detection.

  • I created a simple “detect script” just to simplify the troubleshooting.

      public class DetectHit : MonoBehaviour 
         {
         	void OnCollisionEnter(Collision col)
         	{
         		if(col.gameObject.CompareTag ("Bullet"))
         		{
         
         			Debug.Log("HIT!");
         		}
         	}
         } 
    

This is the code for the throwing rocks:

public class ProjectileShooter : MonoBehaviour {

	GameObject prefab;
	void Start () 
	{
		prefab = Resources.Load("RockPF") as GameObject;	
	}
	
	void Update () 
	{
		if(Input.GetMouseButtonDown(0))
		{
			GameObject projectile = Instantiate(prefab) as GameObject;
			projectile.gameObject.tag = "Bullet";
			projectile.transform.position=transform.position+Camera.main.transform.forward;

			Rigidbody rb=projectile.GetComponent<Rigidbody>();
			rb.velocity = Camera.main.transform.forward * 15;
		}
	}
}

as I said, this is my first post so if you need more information to try help me, just tell me and I’ll post.

Thanks!

Which part of the imported object did you put the collider on?

You didn’t say which program you used to make the imported model but the ones I’m familiar with have child objects already attached to them. Try putting the collider on the child(not the parent)

43342-p1.png

:slight_smile:

edit - All parts have colliders right? at least one object has a rigidbody? Colliders have ‘is trigger’ checked. I know that’s very basic but sometimes a little thing can get overlooked.

:slight_smile: