# Collision in breakout.

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

## Recommended Posts

Hey I'm doing a clone of BreakOut. As you remember there are some amount of blocks you can break, and you control the platform. Now when the ball collide with some block this block: 1. Change his color 2. Disappeared At any case the ball should jump back. Now my physic a little bit bad so I have no idea in what angel ball should jump back. Pay attention that there is no friction forces (air for example) and no gravity. How I can calculate velocity at axises X and Y with? I know the velocity before the collision and I don't know anything about collision angle. Thanks a lot.

##### Share on other sites
dont work with angles. work with vector maths.

##### Share on other sites
The collision causes the velocity the ball hits the wall or block or whatever to flip about the collision normal.

The way you do this depends on your representation. Are you using vectors? Just x and y components? Either way, if your walls are square with the axises (like most breakout games), then it's real easy and you just flip the sign of one of your components. Hit the ceiling, for instance, and you flip the sign of your velocity's y component.

##### Share on other sites
Numsgil
Actually I didn't write the ball class yet so I didn't decided what to use vectors or only x and y. If vectors is easier so I'll use them.
My screen is square (640x480). The blocks are square.
Here is picture if it will help:
http://img248.imageshack.us/my.php?image=btasstb5.gif

Some formulas will help.
Thanks a lot.

##### Share on other sites
Quote:
 Original post by Numsgilif your walls are square with the axises (like most breakout games), then it's real easy and you just flip the sign of one of your components. Hit the ceiling, for instance, and you flip the sign of your velocity's y component.

Formula? if (hitceiling) vel.y = -vel.y if (hitwalls) vel.x = -vel.x

##### Share on other sites
Quote:
Original post by Numsgil
Quote:
 Original post by Numsgilif your walls are square with the axises (like most breakout games), then it's real easy and you just flip the sign of one of your components. Hit the ceiling, for instance, and you flip the sign of your velocity's y component.

Formula? if (hitceiling) vel.y = -vel.y if (hitwalls) vel.x = -vel.x

And if the hit is not perpendicular? If the ball hit the wall/cell with Alpha angel? What should I change? Vx? Vy? Both?

##### Share on other sites
The formula is always the same for the walls and bricks. It doesn't depend of the colliding angle :

// Simply :if(hitWall) speed.x = -speed.x;if(hitCeiling) speed.y = -speed.y;// Alternatively, to be safer :if(hitLeftWall) speed.x = -abs(speed.x);else if(hitRightWall) speed.x = abs(speed.x);if(hitCeiling) speed.y = -abs(speed.y); // If your +Y axis goes up

You might want a different behavior for the paddle (like the ball goes with more angle if it hits the sides of the paddle). You might also want to invert both x and y speeds if the ball hits the corner of a brick.

##### Share on other sites
Ok So I'll check it.
Thank you both.

1. 1
2. 2
frob
15
3. 3
4. 4
Rutin
12
5. 5

• 13
• 12
• 58
• 14
• 15
• ### Forum Statistics

• Total Topics
632122
• Total Posts
3004232

×