Collision of Two Rect
Tim Roberts
timr at probo.com
Sun May 5 01:28:28 EDT 2013
Alex Gardner <agardner210 at gmail.com> wrote:
>
>When rect A collides with rect B they stick when I am wanting A to bounce off of B. I have tried different methods, but none seem to work. My source is here: http://pastebin.com/CBYPcubL
>
>The collision code itself is below:
>------
># Bounce off of the paddle
>if paddle_rect.colliderect(ball_rect):
> y_vel*=-1
> x_vel*=-1
I haven't looked at the rest of your code, but the lines you have here are
going to send the ball back in exactly the direction it came from -- a 180
degree reversal. When a ball hits a paddle at an angle other than head on,
only ONE of the velocities is reversed. When you hit a horizontal paddle,
only the Y velocity is negated. The ball continues in the same X
direction:
\ O
\ /
\/
========
See? The X velocity continues unchanged until it hits a vertical wall.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list