Ball bouncing the wrong direction

If you look closely at the red line. The hit.normal is causing the point I calculate to be outside of the square. So the game thinks no collision occurred.

Vector 2   newHitPosition = hit.point + offsetAlongNormal * hit.normal;

                Debug.DrawLine(hit.point, newHitPosition, Color.red, 5, false);

Is there some other way I can code this to completely avoid this silly problem. It is all because I am using a composite Collider.

In theory the red line should be inside the trigger bounds, because the hit.point is a point on the collider surface and the shapes are the same size. But if that’s not the case maybe there’s some precision error happening or something.

Two ideas:

Give your Composite Collider 2D an edge radius of like .02, so that those corners are rounded slightly which is I think the physics result you’re looking for.

You could also try increasing the size of the brick trigger collider a tiny bit on your brick prefab. Like from 1 to 1.005 or something to allow the trigger to catch raycasts that are very close to the surface.

This scenario is very rare and only occurs from a specific angle.

I’ll try the edge radius, I think that might do the trick.

Not sure if increasing the brick trigger would do good as it may cause a bug with 3 squares in an L shape, where the brick in the bottom left shouldn’t be triggered if hit in the exact middle.

Thanks again jeffreyschoch!

Edit: Edge radius is working perfectly, so far X_X

1 Like