#### Archived

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

# Ball trajectory prediction

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

## Recommended Posts

Hello outthere, I''m working on a Pong game wich includes a small AI. To make it easy for the player to win from the computer it needs to calculate the end point of the ball and then add a confusion factor to make the calc less accurate. But how do I calculate the endpoint of the ball if I only know the distance to the wall and the angle? | | | |....X | .... = Line to the wall X = Ball | = wall Angle = 45 degrees How can i calc where the ball hits the wall? I know how to calc it when I have to lines but I only know one. Any suggestions? Sand Hawk

##### Share on other sites
To work out what line the ball is travelling on, use tan function to get the gradient:

y = mx + b

y - mx = b

Then, to get the y-intercept of the ball, use this formula:

YIntercept = BallY - Gradient * BallX

And put them together:

y = Gradient * x + YIntercept

and that is the line describing the path the ball is going on.

Trying is the first step towards failure.

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

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

• Total Topics
631757
• Total Posts
3002134
×