It's my first RTS game and I'm having trouble finding out how to make infantry take less space than tanks.

Right now I have 1 tank and 1 infantry type ready with sprites, pathfinding, selection and movement mechanics all ready, up and running. The infantry unit is 16x16 and the tank is 32x32 which the size of one tile in my map. How can I make a foot soldier stand or walk with another foot soldier in the same Tile? Should I use 2 versions of the map for each of the unit types to make their pathfinding? In which case there would be problems with coordinates when these 2 types interact with each other like attack and defend which i haven't yet coded.

I'm even starting to question whether a tile based map is even a good choice for a 2D rts game, which is obviously a rediculous question xD.


1 Answer 1


To let your footsoldiers share a tile you should simply position them correctly after the pathfinding found the tile. If you are smoothing your path then each step should lead to the correct position for that unit within the tile.

You can also have a look at flocking. It basically finds a single path for a group of units and moves them as a group. Implemented right you have great control on how the units behave within the group. But if the units are very restricted to the grid this might not be what your looking for.

But for differently sized units on a tilemap you should probably implement clearance based pathfinding. If everything is setup already it should be easy to implement. What you do is give every tile a clearance value: 0 for wall, 1 next to wall, 2 for a extra tile away from a wall, etc how much you need.

A tank that covers two tiles will need a clearance of 2 and the pathfinding system should find a path using the tiles with a clearance value of 2 and above. A flying unit could use 0 or higher.

  • 1
    \$\begingroup\$ Thanks bro, I think I'm going with clearance based pathfinding, for those who are intrested i found a link, it helped me get started harablog.wordpress.com/2009/01/29/clearance-based-pathfinding \$\endgroup\$
    – hio hoi
    Commented Jul 17, 2015 at 14:13
  • \$\begingroup\$ That is what I used when I walked into this. It's a good tutorial. But if you already have a pathfinding system you just need to add clearance to your tiles and change if (!tile.wall) to if (tile.clearance >= unit.clearance) in your pathfinding algorithm and you should be good ;). \$\endgroup\$
    – Madmenyo
    Commented Jul 17, 2015 at 14:18
  • \$\begingroup\$ All right thanks :) but when should i calculate clearance and when to update it ? is it a good idea to recalculate each end of main loop ? or should i recalculate at the beginning of path definition function just before the A* ? \$\endgroup\$
    – hio hoi
    Commented Jul 17, 2015 at 22:24
  • \$\begingroup\$ I don't see why you'd want to recalculate clearance each main loop: just calculate it once when the map is loaded and then again only when the map changes (such as when a wall gets knocked down or a new building appears) \$\endgroup\$ Commented Jul 27, 2015 at 5:55
  • \$\begingroup\$ @hiohoi Sorry, I somehow mist your comment. Like Jeremy says only when the map changes. But you still have to take units into account. Depending on the behavior you want you can update the clearance map when a unit move and look X steps of the path forward to detect a premature collision. Ai behavior can be endlessly coded you just have to stop at what works for your game. \$\endgroup\$
    – Madmenyo
    Commented Jul 27, 2015 at 7:10

Not the answer you're looking for? Browse other questions tagged .