Jump to content
  • Advertisement
Sign in to follow this  
Prot

Collision Detection techniques.

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

Hi folks,

 

I know there are a ton of tutorials and examples on the web. But I am am looking for something very specific (I guess). Until now I always constructed my maps with tiles. With tiles collision detection can be handled pretty easy, because they are rectangles. In XNA/Mono one can easily check for collision via Rectangle.Intersects.

 

What I want to do now is to load entire sprites and use them as ground or walls. The problem is they are never a simple rectangle. In most cases those are shapes which consist of several rectangles.

 

Let's say the example below could be one of the sprites which represent the bounds for a platformer level:

 

[sharedmedia=gallery:images:6593]

 

Are there any techniques to detect collision for a shape like this? I mean sure I could find a workaround like defining multiple rectangles for a single shape.

 

I just wanted to make sure whether there is already a existing approach I could use for something like this.

 

As mentioned above my intention is to use this collision detection for a 2D platformer-ish game.

 

Any suggestions?

Share this post


Link to post
Share on other sites
Advertisement


I mean sure I could find a workaround like defining multiple rectangles for a single shape.

Why do you think that this is a workaround ? It is by far easier to handle each tile as single collision object, because you often need to check an object vs a handful of rectangles only.

Share this post


Link to post
Share on other sites

So assuming I use Mono, what would be a good way to define those collision rectangles? Should I define them manually or is there a way to generate them using the texture? Probably generating collision boundaries from a texture would require a per pixel iteration? This sounds like an overhead for my small project. Can you think of anything else?

Share this post


Link to post
Share on other sites

Hard to say without knowing more details about how you create the texture and build your maps. Do you want to draw one big texture in a drawing-program that will be your entire level, and get proper collision detection against that image?

If so I would suggest manually placing multiple rectangles that fit the parts of texture that require collisions.

Share this post


Link to post
Share on other sites

Hard to say without knowing more details about how you create the texture and build your maps. Do you want to draw one big texture in a drawing-program that will be your entire level, and get proper collision detection against that image?

If so I would suggest manually placing multiple rectangles that fit the parts of texture that require collisions.

 

Thank you, this is exactly what I intended to do. This is also how I implemented it now.

Share this post


Link to post
Share on other sites

There is a much simpler solution for that - in case you have hard edges:

 

You just trace all the contours in your level sprite, build up the edges and the create chained line segments out of it.

Also you can create polygons out of that edges, but you must convert non-convex polygons to convex polygons!

The theory behind is really simple, but implementation is not that easy - just google for contour tracing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!