Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Edison Bright

Collision Problem

This topic is 5725 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wanted to test if a 4x4 bullet sprite collides with a 32x24 enemysprite so I write the following code:
collided = true;
				
				if (bullets.y+4 < enemies[j].y) collided = false;
				if (bullets[i].y > enemies[j].y + 24) collided = false;
				if (bullets[i].x+4 < enemies[j].x) collided = false;
				if (bullets[i].x > enemies[j].x + 32) collided = false;

				if (collided == true)
				{
					enemylist[j] = 0;
					bulletlist[i] = 0;
				}
 
This does not seem to work very well (only about 10% of the time) ... I wonder why?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
The line:

if (bullets.y+4 < enemies[j].y) collided = false;

should be

if (bullets.y+4 < enemies[j].y) collided = false;

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!