Results 1 to 3 of 3
  1. #1
    Reskaillev is offline Member
    Join Date
    Jul 2011
    Posts
    53
    Rep Power
    0

    Default Problems with square collision

    So I need to program the collision of a square. The ball that will hit the object has a velocity of 4pixels/run and doesn't disperse (after collision the velocity of the ball rotates with 90 degrees).
    I make two variables called xball and yball who represent the position of the middlepoint of the ball.

    First I program one of the x-sides of the square to collide if the xball+radius is greater than the xposition of this side of square. I also put the two y coordinates of the square n the IF statement and also put that the xball+radius must be smaller then xposition+5 of the side of the square (since velocity of ball is 4px/run)

    Now I'd like to program the y-sides of the square as well...and now comes the problem:

    If I program the y-sides of the square in the way as the x-side I just did that I will have a "Bugged zone" where the ball will reflect with 180 degrees which isn't something we want...

    Image to clarify:



    Any idea what other method I might use that doesn't have this problem? Or another method?

    Thnx in advance,

    Reskaillev

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,574
    Rep Power
    23

    Default

    If I program the y-sides of the square in the way as the x-side I just did that I will have a "Bugged zone" where the ball will reflect with 180 degrees which isn't something we want...
    Are you sure? Double reflection from top and side or side and top would be 180 degs

    I need to program the collision of a square
    What is the square colliding with?

  3. #3
    Reskaillev is offline Member
    Join Date
    Jul 2011
    Posts
    53
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Are you sure? Double reflection from top and side or side and top would be 180 degs

    If the ball hits the square in its corner --> it should reflect 180 degrees indeed. Problem is that if the ball is in the bugged zone, like the ball comes
    from the left and hits the yellow zone (On the X-side) the program will reflect the ball with 180 degrees and not with 90 degrees like a normal collision woul do. (velocity x AND velocity Y get reversed, while only velocity X needed to be reversed)


    What is the square colliding with?

    The square is colliding with a ball, a circle with radius 10 and middlepoint described by xball and yball
    The ball hits the square and is supposed to be reflected properly, the square doesn't move at all.

Similar Threads

  1. Collision in j2me
    By Ashish_jain in forum Java 2D
    Replies: 8
    Last Post: 06-24-2011, 03:58 PM
  2. 2D - Collision messed up
    By überfuzz in forum New To Java
    Replies: 0
    Last Post: 06-22-2011, 09:20 PM
  3. Collision not being detected
    By CNew in forum Advanced Java
    Replies: 3
    Last Post: 12-06-2010, 07:06 AM
  4. Collision
    By shadycharacter in forum New To Java
    Replies: 0
    Last Post: 04-13-2010, 09:58 PM
  5. Two Problems Rotating and collision detection help
    By jaferris in forum Java Applets
    Replies: 2
    Last Post: 01-07-2008, 11:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •