-2
\$\begingroup\$

to test collision i am using intersect function.

if(this.getBounds_ball().intersects(this.getBounds_rect())) 
{

but the problem is i dont know how to test where the ball is collision from. i was thinking it will have a if statment inside to check if ball is collsion from left. another for right, top and bottom. so 4 if statments? but i dont know how to code it. any ideas? any ideas?

\$\endgroup\$
1
  • \$\begingroup\$ Asking a broad, "how-to-do-this" question is generally not permitted on this site; please see the faq. However, more specific questions about pong, brick-breaker et al. are thoroughly covered. Try this search, see if it helps you find what you need. Pong Collision \$\endgroup\$ Commented May 29, 2013 at 18:02

1 Answer 1

0
\$\begingroup\$

I don't know if it's the best solution but I've used something similar. I found how much one object is overlapping the other and adjust accordingly.

xOverlap = boundsA.X - boundsB.X;
yOverlap = boundsA.Y - boundsB.Y;

then just watch those variables and you should be able to see where you stand. There's probably a better way though I'm still new.

\$\endgroup\$
1
  • \$\begingroup\$ ah i c, the overlaping is making sense but how to test if ball is touch it from left. <br/>i looked online for this but cant find any thing what i am looking for. all tutorial are just for basic intersects(). if you have a good link let me know. \$\endgroup\$
    – raven
    Commented Mar 30, 2013 at 2:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .