Jump to content
  • Advertisement
Sign in to follow this  
Swattkidd

[java] Hit detection

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

Ok well im writing my first game, that i am actually gonna finish :), but its pong and i have the ball moving(left and right only) now i need help witht the hit detection for the ball hitting the paddle. I have the detection down for the paddle's width but im not sure how to keep track of the changing y value. Any tips or ne thing will be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Ok the last code i posted was wrong. I now have a code that gets the ball to bounce when y = 20 (the b value) but i cant get the ball to bounce off ne other part of the rectangle.
Please help

heres what i have for hit detection
a is the value of ball x coordinate
b is the value of ball y coordinate
y is the value for the rectangles y coordinate
and 5 is the width of the rectange(its really 10 but i want it to be 5)

if(a == 5 && b ==y)
{
x_p=+1;
}

[Edited by - Swattkidd on September 27, 2006 8:54:17 PM]

Share this post


Link to post
Share on other sites
Is y the top of the paddle?

if so what is the height of the paddle?

Knowing that you need to check that b is greater than the start of your paddle and that it is smaller than the end of your paddle

small ascii art
-- <--- y start
| p |
| a |
| d | O ))) <---- ball with motion blurrrrr
| d |
| l |
| e |
-- <--- y + height end
^
|
|
5

if( ( a == 5 ) && ( ( b > y ) && (b < ( y + height) ) )

instead of your if.


PS: write any instead of ne please.

hope it helps!

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!