I am trying to shoot a bullet (rigidbody2d, boxcollider2d) to another enemy object (rigidbody2d, kinematic, circlecollider2d). I want the collision point between these two. When they collide, i want a collision particle effect and from the contact point, i want to create 5 rock objects all moving in different directions. How should i achieve this? Problem is that, the contact point i get seems incorrect. Collision particle effect is created when collision happens but the rock objects are created in some other point close to the contact point but not the contact point. Also how to i move the rock objects in different directions after instantiating them?
my code:
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "Enemy")
{
ContactPoint2D contact = coll.contacts[0];
GameObject rock1 = Instantiate (rock, contact.point, transform.rotation) as GameObject;
rock1.rigidbody2D.velocity = transform.up * 20;
GameObject rock2 = Instantiate (rock, newPos, transform.rotation) as GameObject;
rock2.rigidbody2D.velocity = transform.right * 20;
Destroy(coll.gameObject);
Destroy (gameObject);
Instantiate (explosion, transform.position, Quaternion.identity);
}
}