Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

The scenario as you can see in the picture. A ball will be hitting a surface and I want to fairly correctly get the new angle after the collision..

I expect to know the X,Y coordinates of the lines breaking points (The picture below would has 6 lines)

Secondly, if the ball would have a rotation - Is there a standard way of compensate for a "screewed" ball?

alt text

share|improve this question

1 Answer 1

What you need to calculate is the reflection vector;

if v is the velocity of your ball and n is the normal vector of the surface the ball is bouncing from then the the velocty of the ball after the bounce (assuming perfectly elastic collision etc) will be;

v-2(v•n)n

in 2d this will be;

newvelocity_x=v_x-2(v_x.n_x+v_y.n_y)n_x

newvelocity_y=v_y-2(v_x.n_x+v_y.n_y)n_y

share|improve this answer
1  
Good general purpose answer. Just a little note for those making more simplistic rebound game like breakout or pong or the like, if you have a axis aligned bounding box and are not doing real physics (you want the velocity to remain the same) then you can just swap the components of the velocity vector. ie: If you reach the left or right edge of the box, negate the X value of the velocity vector. If you reach the top or bottom, negate the Y value of the velocity. –  James Jan 11 '11 at 23:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.