# OnCollisionEnter2D just flat out not running for certain objects

I am working with the Unity3D Engine in 2D mode. Currently I am trying to make a circle collider bounce off of a composite collider for the walls of my game. The only issue is that for some reason the OnCollisionEnter2D function does not seem to even trigger when the circle collider hits the walls. I have used the log to determine this. I am curious as to why it has this behviour, since it does end up triggering when the player contacts the circle collider? Here is the important parts of the script:

public class sword : MonoBehaviour {

public Rigidbody2D rb;
public CircleCollider2D coll;

public float speed;
public Vector2 trajectory;
public GameObject Player;

// Use this for initialization
void Start () {
speed = 0.0f;
anim = Player.GetComponent<Animator>();
}

private void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log("collided");
if (collision.gameObject.tag == "player")
{
transform.position = new Vector2(-1000, -1000);
Player.GetComponent<movement>().equipped = true;
}
if (collision.gameObject.tag == "solid")
{
ContactPoint2D otherObject = collision.contacts[0];

Vector2 hit = otherObject.point;
Vector2 normal = otherObject.normal;
trajectory = Vector2.Reflect(trajectory, normal);

}
}

private void FixedUpdate()
{
//constantly calculating new velocity
rb.velocity = speed * trajectory;
speed = speed * 0.93f; //drag
if (speed < 0.0001f)
{
speed = 0.0f;
}
if (speed > 1)
{
Physics2D.IgnoreCollision(Player.GetComponent<CircleCollider2D>(), coll, true);
}
else
{
Physics2D.IgnoreCollision(Player.GetComponent<CircleCollider2D>(), coll, false);
}
}
}


More Details: My speed variable is set from a separate script, in case you are wondering. Everything is on the layer 0.. The Rigidbody for player is dynamic, for the ball it is kinematic, and for the walls it is static. Also here is an image of what the game screen would look like, I've labelled the walls and the circle collider (used for a sword).

Thank you.

• Can you give us some details about the rigid bodies and the colliders, particularly is it kinematic and what layers is everything on. – mr-matt Nov 20 '18 at 4:31
• Right, for sure! I added the info into the "More Details" part at the bottom. Basically it's all on layer 0, and the walls are static, player is dynamic, and sword is kinematic. Hope this helps, and let me know if you need other details. – Morgan Nov 20 '18 at 4:40
• check the tag in gameobject – Manoj Balaji M Nov 20 '18 at 5:28