Make a Ball Collide a Diagonal

edited February 2017 in How To...

¡Hi everyone!

I'm a Processing amateur, I don't know much yet about Processing, but the thing is, I have spent the last two days trying to figure out HOW TO Make a Ball Collide a Diagonal line.

I used something like this to make the ball collide a straight line (x or y):

if (position of the ball is bigger than 'this X'){ make the ball change direction; }

BUT i haven't been able to apply this to a diagonal.

PLEASE Help me.... I am very obsessed with this.

Thank you very much!!

Tagged:

Answers

  • Thank you, but I still can't make the ball collide to the line. I mean: change direction when it collides the line

  • Did you check the link provided?

    If you are working with two circles, you check their collisions but checking the distance between their centers and comparing this distance against the sum of their radii. Let's say, if both circles have a radius of one, then a collision occurs when their distance is less or equal to 2:

    if ( distance(circle_center1,circle_center2) <=  (radius_circle1+radius_circle2) )
      { HERE... a collision is in progress}
    

    For distance, you can use the distance function: https://processing.org/reference/dist_.html

    For bouncing effects, you will need to keep track of their previous position. This will be the easiest approach for starters.

    Kf

Sign In or Register to comment.