Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

collision

 
sudde gameeef
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50225
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic