It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes collision Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "collision" Watch "collision" New topic


sudde gameeef

Joined: Mar 21, 2013
Posts: 19
i was test collision between ball and box. i have a ball and long rect(platform) on screen. the collision part works fine. but i want to test where the ball is touch the platform. so if ball touch the ball from left or right or top or bottom. but when i run this. but it is not seem to be going in any of the inner if statments.

Jeff Verdegan

Joined: Jan 03, 2004
Posts: 6109

Add print statements to see the values of your variables and intermediate operations. That way you can see exactly what's happening and learn which of your assumptions are wrong.

sudde gameeef

Joined: Mar 21, 2013
Posts: 19
yeah.... that isnt working. so i want to try some thing else.

1st check for collision

now in side that if statment i can get the over laping x and y. so i know where did the ball collision

now any idea how can i use this information to test where did the ball collide from??
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46320
I think this discussion would fit better in the GUIs forum, so I shall move it.
I think you will have to work out how two shapes collide by comparing their locations. Draw two shapes on a piece of paper.

Example: Two “ball”s will collide with a straight line connecting their two centres. That line will consist of radii of the two shapes, and its length and direction can be calculated by the usual geometrical methods, maybe implemented by the hypot and atan2 methods of the Math class.
I agree. Here's the link:
subject: collision
It's not a secret anymore!