Collision not triggered by box collider

I’m starting out a 2D game. When the rocket collides with the floor nothing happens. Both sprites have box colliders.
The rocket has “Is Trigger” checked.

OnTriggerEnter2D is never called in the rocketScript when it collides with the floor.

Please check the Gameobjects and rocketScript below.

[34443-screenshot+2014-10-28+15.53.24.png|34443]
[34444-screenshot+2014-10-28+15.53.00.png|34444]

-----------------------------rocketScript.cs-----------------------------

using UnityEngine;
using System.Collections;

public class rocketScript : MonoBehaviour {

	float camYSize;

	// Use this for initialization
	void Start () {
		camYSize = Camera.main.orthographicSize;
	}
	
	// Update is called once per frame
	void Update () {
		if (transform.position.y < -camYSize) {
			GameObject.Destroy(gameObject);
		}
	}

	void OnTriggerEnter2D( Collider2D other )
	{
		Debug.Log("Trigger");
	}
}

Both objects should have rigidbodies component to make OnTrigger works.

I don’t see anything wrong with the logic in your code and, sure enough, I can make your exact setup work just fine with a couple of simple sprites in a scene. My suggestions of where you might be going wrong are:

  • The box collider on your rocket is very small (0.0001 wide). If your rocket is moving fast, it is possible that a collision is not being detected as the collider passes through the floor and out the other side in a single frame. Try to change the scale of your objects to make the collider bigger (or slow the rocket down to see if that makes a difference).

  • Your Update() method is destroying the rocket if it falls below the bottom of the camera view, but I notice your floor object has a negative y value. Is there any chance your script is destroying the rocket before it’s had chance to collide with the floor? (try commenting out line 16).