Hi, i use GetContact to retrieve contact point and reflect the object from this contact point. But it looks like not working properly in the long run. Do i use it properly ? What do you suggest ?
-I’ don’t need to retrive all contact points but just the right one.
-Should i reset contact point to get new one each collision or it already gets new points each time on collision ?
public void OnCollisionEnter2D(Collision2D collision)
{
ContactPoint2D contact = collision.GetContact(0);
if (collision.gameObject.tag == "Wall")
{
enemyDirection = Vector2.Reflect(enemyDirection, contact.normal);
rb_Enemy.velocity = enemyDirection * enemyThrust;
}
if (collision.gameObject.tag == "Player")
{
enemyDirection = Vector2.Reflect(enemyDirection, contact.normal);
rb_Enemy.velocity = enemyDirection * enemyThrust;
}
}