Every time a fire my weapon a rigidbody is cloned and fired away.
When it hits an enemy, the enemies OnCollisionEnter(Collision collider)
is called, but not the bullet´s OnCollisionEnter(Collision collider)
.
Both the bullet and the enemy, of course, have attached rigidbodies and colliders. None is set to “is kinematic.”
Why is not the bullet´s function called?
The Bullet code is simple:
public class Shoot : MonoBehaviour {
public Rigidbody bullet;
public float speed = 50;
void Update () {
if (Input.GetButtonDown ("Fire1")) {
Rigidbody clone = (Rigidbody)Instantiate(bullet, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(new Vector3(0, 0, speed));
Destroy(clone.gameObject, 5);
}
}
void OnCollisionEnter(Collision collider) {
Debug.Log ("Bullet collided!");
}
}