Particle / Animation calling by function on collision of 2 moving object

Hi There, I need some guide, how can I call particles and/or animation when 2 moving object collides. Here is the issue the location is not certain!!! objects comes to scene on random location. when collision occurs on random place I wanna call particles and animation as well on that particular position…

thanks in advance.

To test for collisions, you use something like:

OnCollisionEnter(Collision collision) 
{
   ContactPoint contact = collision.contacts[0];
   print(contact.point);
}

So the final line print(contact.point) will give you the Vector where they collided and you can use that for your particles and animation. I have assumed you are in a 3D game. If not, you need to use the 2D versions: OnCollisionEnter2D, Collision2D and ContactPoint2D

Thanks for responding. I have tried that but I am getting error on “contacts” as seen attached photo. do you have any idea how to solve it?

I see you are using OnTriggerEnter2D, not OnCollisionEnter2D. That makes a difference. I don’t believe you can get the collisions point in the same way. The documentation says: “ContactPoint2D can only exist on Collider2D that are not set to be triggers as triggers do not define contact points.”

There is a quite old answer that explains how one person solved the problem using Raycast (note that they were in 3D so, again, syntax will change. You might like to read it.

Thanks for responding. I have tried that but I am getting error on “contacts” as seen attached photo. do you have any idea how to solve it? [200617-untitled.jpg|200617]

I see you are using OnTriggerEnter2D, not OnCollisionEnter2D. That makes a difference. I don’t believe you can get the collisions point in the same way. The documentation says: “ContactPoint2D can only exist on Collider2D that are not set to be triggers as triggers do not define contact points.”

There is a quite old answer that explains how one person solved the problem using Raycast (note that they were in 3D so, again, syntax will change. You might like to read it.

I see you are using OnTriggerEnter2D, not OnCollisionEnter2D. That makes a difference. I don’t believe you can get the collisions point in the same way. The documentation says: “ContactPoint2D can only exist on Collider2D that are not set to be triggers as triggers do not define contact points.”

There is a quite old answer that explains how one person solved the problem using Raycast (note that they were in 3D so, again, syntax will change. You might like to read it.