Computer Science Canada Help with collision detection for Space Invaders Remake. |
| Author: | Degensquared [ Wed Oct 10, 2007 2:42 pm ] | ||
| Post subject: | Help with collision detection for Space Invaders Remake. | ||
Thanks in advance for any help I you can give me I fire the lazer, and it just goes right through enemy, and does not do damage to the enemy. But, certain times, it kills enemys when you are sitting dirrectly below them, without the lazer damaging them.
Thanks Degen. |
|||
| Author: | isaiahk9 [ Tue May 06, 2008 5:34 pm ] |
| Post subject: | Re: Help with collision detection for Space Invaders Remake. |
In theory here is what you should do : Make it so that when the user fires a bullet, that bullet will have coordinates - x will be the x coordinate of your tank when the bullet was fired and the y will increase so it will fly across the screen. Put the bullet in a for loop so that it's y coordinate will be slowly increased, and thus it will be moving upward when you draw it with its y coordinate. Make x and y coordinates for the enemies or targets. Say that if bullet x and y coordinates equal the target x and y coordinates, then that target is damaged. That works - I tried it - but there might be something more efficient out there. However, this is the best I can come up with. |
|
| Author: | Zampano [ Tue May 06, 2008 5:51 pm ] | ||
| Post subject: | Re: Help with collision detection for Space Invaders Remake. | ||
He knows the entirety of coordinates, and used that. Theory is no object. The problem, I think, is here:
You used x comparing conditions, you used '=' as opposed to '>' and '<', requiring the bullet to be at a specific x. And though I can't say, the addition of 30 seems more than a little arbitrary given the size of the enemies. Of course, this approach is use for collision detection for rectangles; for these circular enemies, you will know that the bullet is in the enemy is it's distance from the centre of the enemy is less than the enemy's radius. Thus, use int Distance.PointLine (int, int, int, int) to find the distance between those two points, and you are set for collision detection. |
|||
| Author: | isaiahk9 [ Tue May 06, 2008 6:00 pm ] |
| Post subject: | RE:Help with collision detection for Space Invaders Remake. |
Oh. That works better than mine, Zampano. I just thought that mine was simpler to follow. Guess not. |
|