# Play an effect where a sprite touches a trigger

I have a sprite-based GameObject in Unity to which is attached a RigidBody and a Collider2D. When this GameObject comes into contact with a particular Collider2D Trigger, I want a particle effect to play at the point of contact. This sounds extremely simple to set up and yet I can't seem to find any solution that works, since OnTriggerEnter2D doesn't bother to provide hit coordinates.

Please note that the trigger represents a non-solid space, so adding a solid (non-trigger) collider for hit detection is not a solution.

The sprite is large, so I can't just play the particle effect at its transform position. Raycast is not an appropriate solution for this problem; it doesn't handle nearly enough cases.

• Why the downvote? – user45623 Mar 3 '16 at 19:10
• Depending on the type of colliders you're using, you could try to calculate points of intersection yourself. – zcabjro Mar 4 '16 at 1:14
• Try this otherwise: stackoverflow.com/questions/31641522/… – zcabjro Mar 4 '16 at 1:16

You could use raycast:

If transform.forward isn't right, use whatever vector that represents that direction the object is going in.

OnTriggerEnter(Collider other){
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit))
{
// do something with hit.point
}
}

• This is one of the things I tried, but I guess I didn't do it correctly. I'll give it another shot. I don't feel like it's a great solution because you can't tell the raycast to only look for a specific target, but if I can get it working that should be good enough. – user45623 Mar 3 '16 at 19:40
• This approach doesn't really work. Drawing a ray from the sprite's center doesn't necessarily tell you which part of the sprite is touching the trigger. – user45623 Mar 3 '16 at 22:18
• Hmmmm, sorry to hear that. What if you had a game object on top of the trigger that is the same thing except a collider instead of a trigger, and after you come in contact with it it is deleted so you can so go through the trigger? Not a great solution. – danglingPointer Mar 4 '16 at 1:01