OnCollisionEnter2D not calling, but objects are colliding.
I am attempting to make bullets explode upon contact with a wall, or anything actually. The bullets are colliding but the OnCollisionEnter2D is not being called at all. (Scripts have been tested with current commented lines, I've heard that the destroy is bad) Its also not being called when the bullets collide with each other.
This is the bullet class, the "AddForce"/Shooting action is done by the gun class. Just your basic AddForce.
public class Bullet : MonoBehaviour {
public float lifeSpan;
public float damage;
public GameObject boomBook;
private float accumulator = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
accumulator += Time.deltaTime;
if(accumulator > lifeSpan) {
//explode();
}
}
void onCollisionEnter2D (Collision2D col) {
Debug.Log ("Hi");
//col.gameObject.SendMessage ("takeDamage", damage);
//explode();
}
private void explode() {
GameObject b = (GameObject) Instantiate(boomBook, transform.position, transform.rotation);
//Destroy(gameObject);
}
}
The bullets inspector stuff:
And a wall's inspector stuff:
UPDATE I Just tested OnTriggerEnter2d by placing a generic trigger area on the map and the bullets did Debug.Log when going through that. So it is specifically a problem with the collision.
Your answer
Follow this Question
Related Questions
Pipe Game Water Flow 0 Answers
2D colliders doesnt work with Gravity Scale = 0 0 Answers
Issues with 2D collision/overlap detection,Help detecting 2D collision/overlap 0 Answers
Why doesn't my box collider work? (Unity2D) 2019.2.13.f1 0 Answers
Object Colliding while passing along another object . 0 Answers