• Advertisement

Archived

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

Collision Problem

This topic is 5517 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