Sign in to follow this  

[java] Hit detection

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

This topic is 4093 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this