IOCT Masters in Creative Technogies
Major Project
An augmented reality game based on "Breakout"

Monday 16 June 2008

Collision detection: Paddle

The ball must be projected on to the paddle and the point at which the ball would have contacted the paddle and this point must be calculated. As the paddle has curved edges I tried to angle the edges of the paddle collision detection lines, however, having tried to use the intersection of two lines I could not get the collision detection process to work as desired. I have decided to extend the line across the top of the paddle, so that the collision occurs whenever the ball collides within the length of the paddle.

paddley = top edge of paddle in the y axis

Test:
paddley > position in y – radius

y1=paddley – ball position y + radius
t=y1/vely
x1=t*velx


Test condition, ensure ball hits between paddle edges:
previous ball position x + x1 > paddle position – paddle half width
&&
previous ball position x + x1 < paddle position + paddle half width

ball position x = previous ball position x + x1
ball position y = previous ball position y + y1
vely=-vely
ball position x = ball position x + (1-t)*velx
ball position y = ball position y + (1-t)*vely