wood burning stoves 2.0*
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
Author

collision

sudde gameeef
Greenhorn

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
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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
Greenhorn

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
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
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.
 
GeeCON Prague 2014
 
subject: collision