Hi everyone… I got an issue that I can not solve and do not know how or what to search for anymore… I have tried to fix this for a week… So giving this forum a majestic try!
My game i am developing got lots of collisions between different balls going on… I’ll take the game of Pool to explain my problem that is pretty similar and does not need deep explanation.
What happens is: Collision between moving balls (2D) on a table.
Expected is: That it is a natural collision between the two balls… and yes that happens…
Issue I got is that maybe 1 out of 50 collisions the balls get stuck, and result is that both ball 1 and ball 2 goes to the same direction.
My collision code looks like this, and the ball objects are using Rigidbody2D , and circlecollider2D.
private void OnCollisionEnter2D(Collision2D col)
{
// Normal
Vector3 N = col.contacts[0].normal;
//Direction
Vector3 V = velocity.normalized;
// Reflection
Vector3 R = Vector3.Reflect(V, N).normalized;
// Assign normalized reflection with the constant speed
rigidbody2D.velocity = new Vector3(R.x, R.y) * (speed);
}
Any suggestions on why this happens and how to prevent this?