Archived

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

Sand_Hawk

Ball trajectory prediction

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 this post


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

Gradient = Tan(Angle)

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.

Share this post


Link to post
Share on other sites