1
\$\begingroup\$

I have a 2D Ball that might go against a wall.

If the Ball goes against the wall perpendicularly, it will just invert its direction (assuming no air resistance and no bounces that should make its speed change).

My problem is: how the velocity of the Ball changes when it goes against a corner?

This is the case I didn't figure out how to handle:

\$\endgroup\$
0
3
\$\begingroup\$

Here is what I'd do:

enter image description here

Upon detection of the circle and the corner (this will be, IMHO, the most complicated thing to do), take the angle of the line segment between the centre of the circle and the corner (in RED), calculate the perpendicular to that (the tangent, in BLUE), and have the vector in (PURPLE) be reflected to the vector out (YELLOW).

It's probably the exact same thing that you're currently doing with the box sides, but instead of using a predefined tangent, you compute the tangent based on the position of the circle and the point of impact.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .