How can I call OnTriggerEnter2D from the object with the trigger on it?

So uh, I’m trying to make a one way platform, and it’s proving to be difficult.

I’m trying to use a trigger object that goes underneath the platform, and when the player enters the trigger, it does the Physics2D.IgnoreCollision thing between the player’s collider and the platform’s collider.

The problem I’m having is that I’m trying to call OnTriggerEnter2D/Exit2D from a script on the trigger object, and I don’t think that’s working. Is there some solution to this?

Edit: I should have elaborated more. I need to figure out how to detect if the player has entered the trigger from the trigger object itself, not the player. Is that possible?

In order to detect collisions, at least one of the elements colliding should have a RigidBody, in this case a RigidBody2D, usually you add this to your moving element (the player) as best practice. Does your player have this component attached?

Hope this helps

Trigger messages are always sent to both objects involved. If your platform trigger is a static trigger collider it will receive an OnTriggerEnter2D event when the player objects enters the trigger.

However, If your platform collider is a child of another rigidbody object, the rigidbody will receive the event and not the child collider. This is because a rigidbody will “collect” all colliders which are a child of itself and use it as compound collider.

You would need to attach a kinematic rigidbody to your trigger object if you want to receive the message there in that case.

You might want to take a look at:

http://docs.unity3d.com/Manual/CollidersOverview.html