# pixel perfect collision detection

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

## Recommended Posts

I'm making a Metroid-like platformer as a side project, trying a few new concepts, including side scrolling and pixel-perfect collision detection. I don't want to perform too many detections because I want the number of objects potentially on screen to be near limitless. Currently, an object recieves an update function call being passed the number of milliseconds since its last call, at which point, if it moves, it tests to see if its new position is possible through collision detection. There are a couple problems I'm afraid of. First, if an object's update is too infrequent, it may warp through walls, etc. because its being tested on the other side of the wall. Second, when an object fails a move, it needs to be determined if it can move a little less farther (IE, a bullet hit the wall about half way through its update). Another concern is that when two moving objects should collide, they may likely miss each other if the collision happens long before they are actually updated. So what I'm wondering is if there is a way to simplify collisions to approximate circles so I can cheaply find out when and where objects collide and then use pixel perfect to clean it up and be more accurate. Any insights are appriciated...! thanks ~Stephen

##### Share on other sites
Quote:
 Original post by StepheltonI'm making a Metroid-like platformer as a side project...

Awesome, I'm a huge fan.

Quote:
 ...if an object's update is too infrequent, it may warp through walls, etc. because its being tested on the other side of the wall..

You could solve this by using line collision in conjuncture with your sphere colision. So you define a line from where the object started and where it ended. When testing for collision with object X, you find which point on the line is closest to object X, and do the collision check there (there is a pretty simple formula for 'closest point on a line' somewhere).

But honestly, i wouldn't worry about this too much for now. Just make sure your collision code is modular enough so that if you need to add this later, you can easily.

Quote:
 Another concern is that when two moving objects should collide, they may likely miss each other if the collision happens long before they are actually updated.

I'm not really sure what this means.

Quote:
 So what I'm wondering is if there is a way to simplify collisions to approximate circles so I can cheaply find out when and where objects collide and then use pixel perfect to clean it up and be more accurate.

Absolutly! Everything should do a simple sphere check before checking through pixels. Steps would be something like this

1) Maybe some huge eliminator (like are the objects even on the same screen)
2) (if they are) Check if the object's spheres are colliding
3) (if they are) Preform pixel perfect collision check

Can't wait to see the game!
Matt Hughson

##### Share on other sites
Matt, thanks for the reply. Zelda and Metroid have always been my favorite games. I'm heading a larger Zelda project hosted on sourceforge at http://ztds.sourceforge.net. It's goals are aimed quite higher than my Metroid game, so its proceeding quite a bit slower.

Quote:
 Another concern is that when two moving objects should collide, they may likely miss each other if the collision happens long before they are actually updated.

By this, I was referring to when two objects move and should intersect, namely projectiles. Probably isn't a concern, but part of the fun of making a game is considering its limitations and trying to improve them.

I hadn't considered a formula to find the "nearest point." That is probably a good solution; but it may still be the case, particularly with large objects, where they would colide before the point where their lines intersect, or before the point where they are closest.

Perhaps I can make an algorithm to find the rate of change of the distances between the two lines and use it to find exactly when the distance between the objects becomes equal to the sum of the radii, and hence a colision. Of course it doesn't really matter since I'm going to then be doing pixel perfect detection. I guess what I want to avoid is objects colliding after they should.

Does anyone have any good resources for pixel perfect algorithms? I've got one devised which should be about as efficient as they get, but I'd like something to compare it to.

Thanks again.
~Stephen

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633699
• Total Posts
3013416
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!