How to find the resulting angle of a ball hitting a wall in 2D

So there's a ball moving on a 2D plane with any vector. When it comes into contact with a collider, it should reflect in a linear fashion. What formula should be used in order to find the angle that this new direction should have? The pieces of information that are known are:

• The X and Y velocity of the ball when it was hit
• The angle it was travelling at when it was hit
• The point of contact

I've found many solutions for if the ball can only hit vertical or horizontal walls, but have yet to find a one for a general case.

• We usually don't do this with angles, but by reflecting the velocity vector along the collider's normal. Do you have these two vectors, or are you required to work in angles here? Nov 8 '18 at 8:19
• I have the ball's vector and angle. I'm wondering how to find the collider's normal which I've collided with. If I'm able to find the resulting x and y components of the reflected vector then I can find the new angle too, I know the equation to do that. How would I find the collider's normal and the resulting vector? Nov 8 '18 at 21:21
• How are you detecting the collision in the first place? OnCollisionEnter2D, OnTriggerEnter2D, raycasts/circlecasts, or some other method? Nov 9 '18 at 0:00

Exit angle is equal to entry angle. In the sketch, angles labeled X are equal to each other and angles labeled Y are equal to each other. The line is the normal (perpendicular) to the wall (rectangle)

However, if you are doing this programmatically (and I assume you are, since you are asking about Unity on the game dev so) you may be better off not worrying about what the resulting angle will be.

What I suggest you do, is take your balls velocity vector, rotate it by an amount equal to the slant of the wall, flip the x-component of the vector (assuming you rotated so your wall would lay flat), then rotate the resulting vector back again.

If your ball has no velocity, since you seem to only have an angle, simply create a vector of magnitude 1 (or whatever) and the correct angle, and apply process above.

• This description helped me come to the correct result for my specific issue. I believe your way of doing it is correct so I'll mark it as so. Thank you. Nov 20 '18 at 4:07