#### Archived

This topic is now archived and is closed to further replies.

# Need help with collision

This topic is 5823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am making a pong game and its just about done but the collision of the paddles and the ball. I am not great at math but I have an alg book with me, havent looked at it though beause I am not sure what to look for. But I would like a simple algorithm for making the ball bounce off the paddle and the wall(which should be the same I think..) Also to make things easier for myself and not having to ask another question could you display it in programming code. I dont think I need to tell you what the values I have but I will put in the alg in the code. There doesnt need to be checking for what side the ball hit the paddle I just want a mirror rebound on the ball. Thank you.

##### Share on other sites
If the Ball get close to the wall/paddle just reverse the x/y increaser.

xred = value to reduce/increase x by
yred = value to reduce/increase y by

assuming 0,0 in lower left corner

if (ball.xmax >= wall.xmax || ball.xmin <= wall.xmin) {
// rebounce
xred *= -1.0f;
}

if (ball.ymax >= wall.ymax || (ball.xmax >= paddle.xmin && ball.xmin <= paddle.xmax)) {
// rebounce
yred *= -1.0f;
}

x = x + xred;
y = y + yred;

if (y < 0) GAME_OVER;

hope this helps you

1. 1
Rutin
25
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633311
• Total Posts
3011306
• ### Who's Online (See full list)

There are no registered users currently online

×