so I'm making a 2D platformer game with 360° shooting in Unity. I want my bullets to be reflected when they hit something (think billiard).
The code below works if bullets ricochet off of the ceiling or the floor. The problem is that when i hit something from the side the new direction of the bullet is exactly 180° off.
private void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag != "Player" && col.gameObject.tag != "Bullet")
{
ContactPoint2D[] contacts = new ContactPoint2D[10];
col.GetContacts(contacts);
Vector3 currentBulletMoveVector = transform.right;
Vector2 newBulletMoveVector = Vector2.Reflect(currentBulletMoveVector, contacts[0].normal);
transform.right = new Vector3(newBulletMoveVector.x, newBulletMoveVector.y, 0);
}
}
Any advice on where I went wrong or how to fix this?