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'm writing a 2D tile based RTS. And I want to add a 'pseudo 3D' feature to it - bridges over the rivers.

I havent't start any coding yet, just trying to think how it fits the collision detection model. A boat passing under the bridge and a unit moving over the bridge will eventually occupy the same cell on the map. How to prement them from colliding?

Is there a common approach to solve such a problem? Or I need to implement a 3D world to do this?

share|improve this question
    
well if you are doing a tile based system, you could add something like an "isOccupied" method for each time. Just have the bridge check below itself and above. –  Benjamin Danger Johnson Nov 16 '12 at 23:50
1  
if ground units don't interact with water units, you might handle separatly collisions for both sets of units. And maybe consider a boat at the harboor is a ground unit to allow interactions like the player/a npc entering the boat. –  GameAlchemist Nov 17 '12 at 14:10
add comment

2 Answers 2

up vote 7 down vote accepted

You'll basically have to create a third dimension, though in the simplest case it can consist of just two values: "on ground/on bridge" and "on water/below bridge".

An inspiration can be found in the way Advanced Strategic Command does it: Units occupy a specific height level, can only move around on height levels fitting to their type unless there are specific features allowing them to do otherwise (for example runways for aircraft) and changing them usually costs movement points, with penalties on some height levels or others. A tile can be occupied by any number of units as long as each is on a different height level.

In case of ASC, the levels are:

  • space
  • high altitude (bombing)
  • medium altitude (interceptors)
  • ground attack altitude
  • ground (most ground units and hovercraft, even over water)
  • water
  • partially submerged (submarines)
  • submerged ("hidden" submarines)
share|improve this answer
    
Thank you, Martin! –  aleguna Nov 16 '12 at 11:32
add comment

You can add a simple attribute to each tile that specifies its level.

So for example:

tileA.layer = 0 // Will be at the bottom
tileB.layer = 1 // Will be above level 0, on top of it. 

// Add tiles to layered list
List<List<Tile>> tiles = new List<List<Tile>>();
tiles[0].add(tileA);
tiles[1].add(tileB);

// Draw 'em in the right order!
void Draw(List<List<Tile>> tiles) {
    foreach( var listOfTiles in tiles ) {
        foreach( var tile in listOfTiles ) {
            tile.draw();
        }
}

Now you can sort your tiles depending on their layer values and draw them bottom -> top! This will make it look like you have a certain depth in your game. Most tile engines support this. Another cool thing you can add is transparency to your textures so you can see through to the bottom layer.

This can be done with water for example - imagine the water at lvl 1 and then the ocean floor at lvl 0. If the water texture is somewhat transparent, you will be able to see the ocean floor from above.

share|improve this answer
    
Thank you! Can't accept both answers unfortunatelly :) –  aleguna Nov 16 '12 at 12:01
    
@aleguna No worries! It's just fun to help out. :) –  Zolomon Nov 16 '12 at 20:59
add comment

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.