Jump to content
  • Advertisement
Sign in to follow this  

Pixel-based collision detection with sphere

This topic is 2120 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


I am currently making a pixel based 2D table tennis game where I need to to find the exact point the ball hits the table.
For simplicity reasons I have't programmed the spin of the ball yet.
Can anyone help me with formulas or something else helpful?


Share this post

Link to post
Share on other sites
You can get the contact point using this formula:

Pc = C - n[(C-P)dot(n)]

Pc: contact point
C: ball's center
n: the unit vector normal to the table and pointing upward
P: any point on the surface of the table

The quantity [(C-P)dot(n)] is the closest distance from the ball's center to the table. If this distance is greater than the ball's radius, there is no collision.. Edited by m_a_s_gp

Share this post

Link to post
Share on other sites
If you want an analytic solution, neglecting friction:

y(x) = y0 + vy*(x-x0)/vx - 0.5 * g * [(x-x0)/vx]^2

vx,vy : initial speed in x and y directions
y0,x0 : initial position
g : acceleration due to gravity

impact is when y(x) = h + r
where h is the height of the table and r the radius of the ball

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!