• ### Popular Now

• 13
• 15
• 27
• 9
• 9

#### Archived

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

# Collisions ??? Box/Ball

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

## Recommended Posts

Well , i´m stuck, i´m making a pong game , all was fine until I reached the collisions -->

struct struct_ball

{
double x;
double y;
double vx;
double vy;
double Speed;
}struct_ball;

struct_ball Ball;

{
double x;
double y;

// Right side of the pad --> This work ok

if (((Ball.x >= Players[0].x) &&

((Ball.y >= Players[0].y) &&

{

Ball.vx = -Ball.vx;

}

// Top of the pad --> does not work ! dunno why

if (((Ball.y >= Players[0].y)&&
&& ((Ball.x >= Players[0].x) &&

{

Ball.vy = -Ball.vy;

}

[\code]

The above piece of code test the Ball against the left pad, but my question is how I can test the top and botton sides of the pad against the ball ?

Or better , there is another way to test collisions with objects ?
Maybe perfect pixel collision ? can someone show me ?   

##### Share on other sites
Don''t you want to take into account the size of the ball? For your tests you use the dimensions of the paddle, but not of the ball.