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 have been looking at the following question:- Tile coordinates and am thinking of using this for collision detection in my tile game.

The set up in my game is similar to this, in that there is a grid of tiles, and the sprite will move to (x,y) coordinates. However, if I were to have an object such as a box in my world that is made from multiple tiles, how would I get the collision detection to work?

Any ideas welcome.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

There are several ways to solve the problem of objects that are larger than your tiles.

Perhaps the easiest way is just to add the entity to every tile that it intersects with. Essentially the entity is in a wide range of tiles at any time. The is simple to implement but doesn't scale well for performance if your entities vary greatly in size.

A more flexible solution would be to use hierarchical tiles, where you have several tile sizes, and you place entities into the set of tiles that best fits their size. This works well if you have a fixed number of different entity sizes.

The most flexible solution would be a quadtree, which starts with very large tiles and recursively splits them so that they always fit the smallest object.

I drew a diagram of some simple cases to illustrate the ideas. The green boxes are the tiles that the gray object would be added to in that tile structure.

enter image description here

share|improve this answer
3  
+1 for visual aids. However, once one makes the decision to go with the quad tree route, I would stop thinking in terms of tile grids altogether, since that abstraction is no longer useful. –  PlayDeezGames Feb 16 '12 at 17:46
    
Thank you for the response, I will try this concept later on this evening. –  VisionIncision Feb 17 '12 at 17:52

A number of different ways to approach this, all equally valid.

One of them is to break your multi-tile box into its component single tile objects.

The reason for picking tile-based over non-tile based is because dealing with tiles simplifies a number of things.

However, it also complicates a number of things.

You've just run into one of them.

share|improve this answer
    
Hi, thanks for the response, I am not sure exactly what you mean by "One of them is to break your multi-tile box into its component single tile objects." –  VisionIncision Feb 16 '12 at 16:24
    
you have an object too big for a single tile, yes? so, one of the ways it to break it into a number of smaller objects, so that each object fits in its own tile. One of the alternatives to this is to track larger multi-tile objects outside of the standard tile structure, which means you are no longer strictly tile-based. If, let us say, you have a four tile sized object, you might split it into the northeast, northwest, southeast, and southwest corners of the object, and place each of the objects in separate tiles. –  PlayDeezGames Feb 16 '12 at 16:28

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.