# triangular collision detection

This is a discussion on triangular collision detection within the Game Programming forums, part of the General Programming Boards category; I'm trying to make a space invaders clone, and I want to check to see if a bullet has hit ...

1. ## 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

2. 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