Odd behaviour bounce

Yes folks, another bonce problem.

The code I have for calculating bounces is working 99%. Just every now and then one or both colliding objects decide to head off in an incorrect direction.

I have read somewhere (a while ago) if you’re performing collision testing with many objects you need to run the collision code, then check that there are no other collisions around these objects before continuing your loop. I can’t remember exactly what that article was so I’m not sure if it applies here. And the tree created for checking this would probably pop my head.

I haven’t watched for hours, but I know this is happening between two objects heading towards each other without the interaction of any 3rd object. It’s seemingly random and not reliant on any particular angle.

Could someone please have a quick look and tell me what I’m doing wrong, or at least not accounting for?

Many thanks…

` m1.Position = m1.LastGoodPosition
m2.Position = m2.LastGoodPosition

                    Dim n1 As Vector2 = Vector2.Normalize(m2.Position - m1.Position)
                    Dim n2 As Vector2 = Vector2.Normalize(m1.Position - m2.Position)

                    m1.Direction = Vector2.Reflect(m1.Direction, n2)
                    m2.Direction = Vector2.Reflect(m2.Direction, n1)`

Normalize make the length of a vector between 0 and 1.
It is not the normal to a vector which mathematically would be a plane.
Usually, you need the normal to the surface to use reflect.
You have to know the normal of the plane where the collisions occur