Jump to content
  • Advertisement


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.

If you intended to correct an error in the post then please contact us.

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!