object detection

This is a discussion on object detection within the Game Programming forums, part of the General Programming Boards category; i am making a arkanoid like game and need help making the simple object detection between the ball and a ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    17

    object detection

    i am making a arkanoid like game and need help making the simple object detection between the ball and a block. i dont know how to determine which side of the block the ball hits.
    Drink Yer Wilk

  2. #2
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    17
    ok, il make myself a little bit clearer:

    i want to know how to determine what side of the block the ball hit like if the ball hit a side i would reflect the ball and mirror its x speed but the prob is is i dont know how to determine if it is in a certain side.
    Drink Yer Wilk

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    This is how I solved it in my ball game:

    Split every block into 4 parts (see picture below). When checking if the ball overlaps the block, also check which of the four triangles it is in. If it's in the top one, it's most likely the ball came from above. If it's in the left one, it's most likely it came from the left. And so on...

    Obviously, this has some flaws if the ball's speed is too great, but may be a place to start.
    You could also combine it with checking the ball's speed. If it enters the top triangle and the Y speed is going upwards there is certainly something wrong (the ball went through the block) .
    Attached Images Attached Images  
    Last edited by Magos; 04-17-2003 at 08:18 AM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Also, a theoretical solution I came up with is to "draw a line" from the balls last position to its current position. Then check which line of the block's four edges it overlaps. If none - no collision. If one - that's the side it collided with. If many - Check which edge was overlapped "first" (is closest to the last ball position).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using this as synchronization object
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 03-22-2008, 08:49 AM
  2. circular doubly linked list help
    By gunnerz in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2007, 09:38 PM
  3. Replies: 60
    Last Post: 12-20-2005, 11:36 PM
  4. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 05:33 PM
  5. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 05:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21