- Home /
Question by
emvaernes · Dec 05, 2015 at 05:29 PM ·
collisioncollision detectioncollision2d
collisions does not get detected every time
I use this script to detect if a bullet collides, and it works most of the time. But sometimes, I don't know why, the collision does not get detected. Even though when I play the game, it is colliding and bouncing. Is it because the collision happens too fast, because most of the instances of when the collision doesn't get detected, is when the bullet hits the side of an object, and bounces off right after that. I use the collisionDetectionMode because the object is moving quite fast, but is it not good enough?
public class DestroyBullet : MonoBehaviour {
void Start(){
Debug.Log("started");
gameObject.GetComponent<Rigidbody2D> ().collisionDetectionMode = CollisionDetectionMode2D.Continuous;
}
void OnCollisionEnter2D(Collision2D coll)
{
Debug.Log("collision");
Destroy (gameObject);
}
}
Comment