Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Collider not detecting any collision :(

Discussion in 'Physics' started by sush333, Feb 23, 2015.

  1. sush333

    sush333

    Joined:
    Jan 26, 2015
    Posts:
    32
    I have a bullet and a enemy. Both have colliders. I have used the same code for the player bullet hit and it works but when i copied and pasted 90% code of the same script, the enemy bullet doesn't detect any collision, neither with player nor with any other object.

    here is some code-


    using UnityEngine;
    using System.Collections;

    public class EnemyShootingBullets : MonoBehaviour {

    public float speed;
    //explosion or vibration or spark or anything that enemy bullet impact would make on the player
    public GameObject Explosion;
    //the box surrounding the city as a boundry limit to player(may not for the enemy)
    public GameObject cityBoxSquare;
    void Start ()
    {
    //Physics.IgnoreCollision(cityBoxSquare.collider, collider);
    rigidbody.velocity = transform.forward * speed;
    Destroy(gameObject,10);

    }

    void OnCollisionEnter (Collision col){
    Debug.Log("Enemy bullet hit something");
    string nam = col.gameObject.name;
    if (nam == "Peterling"|col.gameObject.tag == "Player") {
    Debug.Log("Peterling hit");
    //call a function from game controller script to reduce player health






    ContactPoint contact = col.contacts [0];
    Quaternion rot = Quaternion.FromToRotation (Vector3.up, contact.normal);
    Vector3 pos = contact.point;
    Instantiate (Explosion, pos, rot);
    Destroy (gameObject);

    }
    }


    }



    ____________________________________________________________________
    additional info-

    none of the collider is on trigger selected.
    The same code was working for my player bullet hitting the enemy.

    ANY SUGGESTION WOULD BE APPRECIATED.
     
  2. tranos

    tranos

    Joined:
    Feb 19, 2014
    Posts:
    180
    Experiment by changing rigidbody's "sleeping mode" to "never sleep".
     
  3. POiD

    POiD

    Joined:
    Dec 18, 2013
    Posts:
    4
    Very Project Settings -> Physics to make sure you hadn't turned off collisions between the layers of your bullet and your enemy.