Detecting Items using colliders (2D Game)

Hello.
this is what I’ve been doing. (2D game project)

  1. Items are floating around(with Rigidbody2D, CircleCollider).
  2. generate triangle mesh dynamically(with PolygonCollider).
  3. get Items within triangle mesh.

but collision detection won’t work between items and triangle.

someone please let me know what’s wrong with this…

I have tried turn isTrigger both on/off, and isKinematic both on/off.

alt text
alt text

using UnityEngine;
using System.Collections;

public class PolygonColCtr : MonoBehaviour {

	
	void OnCollisionEnter2d (Collision2D coll)
	{

		if (coll.gameObject.tag == "ITEM")
		{
			Debug.Log ("Caught ITEM!");
	
		}

	}

}

Instead of OnCollisionEnter2D, you could ask each item if it’s inside the triangle’s bounds

foreach (GameObject i in GameObject.FindGameObjectsWithTag("ITEM"))
{
    if (this.GetComponent<PolygonCollider2D>().bounds.Contains(i.transform.position))
    {
        Debug.Log("Caught ITEM!")
    }
}

@Crafterguy3x3
that was such a mistake. thank you but collider still won’t work.

is this component only for the crashing between outlines of two objects?

(won’t be working inside the object like what I’m trying now?)

thank you for your comment btw, I’ve been stuck in here way too long :frowning: