Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am designing a game for Android using Surface View. When a bullet hits any point on an alien it should blow the alien up. I wrote some code to detect collisions, but my code only triggers when my bullet hits the exact (x,y) coordinates of the alien. How do I write the collision-detection system so the alien will blow up wherever the bullet hit it?

share|improve this question
3  
You've explained exactly nothing. –  knight666 Jun 19 '12 at 10:00
add comment

2 Answers

In most cases I was happy with measuring the distance between the center of the sprite and the center of the bullet. When it is small enough blow up the unit...preferably a greedy money-obsessed "human," not a good and green "alien!"

Pythagoras and his theorem are your friend...

share|improve this answer
add comment

You need to check if you bullet is touching any part of image, if image is rectangular you just check if bullet is inside rectangle. If your image is more complex then rectangle you need to do pixel perfect collision, that means go through all your image and check if your bullet hit some colored spot.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.