我正在尝试将子弹(rigidbody2d,boxcollider2d)射向另一个敌方物体(rigidbody2d,kinematic,circlecollider2d)。我想要这两者之间的碰撞点。当它们发生碰撞时,我想要一个碰撞粒子效果,并且从接触点开始,我想要创建 5 个岩石物体,它们都在不同的方向移动。我应该如何实现这一目标?问题是,我得到的联系点似乎不正确。碰撞发生时会创建碰撞粒子效果,但岩石对象是在靠近接触点而不是接触点的其他点创建的。另外我如何在实例化它们后将岩石对象向不同方向移动?
我的代码:
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);
}
}