Public Group

#### Archived

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

# Breakout clone, ball´s moving

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

## Recommended Posts

I´m working out with Breakout clone (C++/OpenGL) and now I need some help with figuring out how to move ball correctly. Ball has a variable angle (direction). Question is: How can I increase/decrease ball x and y variables correctly based on this angle variable? Thanks.

##### Share on other sites
I don't know openGL, but if you know the angle you want the ball to travel in, and the total velocity, then x_increment = velocity*cos(angle); and y_increment = velocity*sin(angle);

that will give how much x and how much y to move it by every time to move in that angle. The angle will probably have to be in radians. If you're not familiar with radians, the formula for degrees to radians is r=(pi/180)*d .

You'll have to find a way to save precision among the types you're using.

[edited by - masque01 on March 21, 2004 1:39:14 PM]

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

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

• Total Topics
631766
• Total Posts
3002221
×