General Category > Game creators corner

Conditional blocking (only some units)


Hi guys,

How would you implement the following: I have a map with land and sea. I have land units that cannot go to water cells. However, I have "amphibious" units that can also go on the water.

If I set the cells as blocking, then none of the units can go on the water. How can I make this blocking only for ground units? Can I somehow use the "cost" property of the cells? I'm not using this property at all by the way. I don't even know what it does. I guess it's some movement cost modifier but that's just my intuition.

* Also, keep in mind that I still want units not to step on each other so I can't just put different types of units on different layers. Also, there are other harder blocks as cliffs and hills that no unit can go through.


Here the best solution would be the area stuff. It can be used as a sort of filter for pathfinding.
In your example you need two different area ids like land and water.
The xml code for the ground objects would look like:

--- Code: ---<object id="water1" namespace="grassland_tileset" blocking="0" static="1" area_id="water">
<object id="ground1" namespace="grassland_tileset" blocking="0" static="1" area_id="land">

--- End code ---

For the units:

--- Code: ---<object id="land_unit" namespace="grassland_tileset" blocking="1" static="0">
   <walkable_area id="land"/>
<object id="amphibious_unit" namespace="grassland_tileset" blocking="1" static="0">
   <walkable_area id="water"/>
   <walkable_area id="land"/>

--- End code ---

Cliffs and hills can still be set to blocking like the units or buildings.
I hope that helps :)

With the cost property it's possible to make movement on cells cheaper or more expensive. So if your ground have different costs the units will try to move on the cheapest terrain, as example your map could have land with normal cost, swamp with 2x cost and streets with 0.5x. So the units would prefer the streets but would also use both other terrains.
The cell speed is similar but the change concerns only the real movement speed.

Thanks! Will implement it ASAP.


[0] Message Index

Go to full version