Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

collision

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Marshal
Posts: 79632
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic