Thread: triangular collision detection

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    triangular collision detection

    I'm trying to make a space invaders clone, and I want to check to see if a bullet has hit the triangular ship. I can't really figure how to do this, so I've put in this makeshift solution:
    Code:
    for (i = 1; i <= numbullets; ++i) 
        if (bullet[i].x >= ship.x - 10 && bullet[i].x <= ship.x + 10 &&
            bullet[i].y >= ship.y - 15 && bullet[i].y <= ship.y &&
            bullet[i].dy > 0) {
            ship.life -= 10;
            killbullet(bullet,i,numbullets);
        }
    but this is letting bullets hit the empty space around the skinny end of the ship. Does anyone have a better way to run this test?

    complete source/game
    Illusion and reality become impartiality and confidence.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    If you don't want to do a "point-within-polygon" type algorithm, you can approximate a triangle with a group of rectangles - imagine a stack of rectangles with the same height and decreasing width. Testing if a point is within a rect is easy.

    Just a thought.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Collision Detection Problems
    By Dark_Phoenix in forum Game Programming
    Replies: 1
    Last Post: 12-17-2006, 03:25 PM
  2. Collision Detection
    By Grantyt3 in forum C++ Programming
    Replies: 3
    Last Post: 09-30-2005, 03:21 PM
  3. bounding box collision detection
    By DavidP in forum Game Programming
    Replies: 7
    Last Post: 07-07-2002, 11:43 PM
  4. collision detection
    By DavidP in forum Game Programming
    Replies: 2
    Last Post: 05-11-2002, 01:31 PM
  5. Replies: 4
    Last Post: 05-03-2002, 09:40 PM