1
\$\begingroup\$

In my tile map, created with 'Tiled', I placed some tiles that need to be avoided by my mobiles. Tiles like water or obstacles.

The entities "wander" in the map, choosing random directions, and their position are in world coordinates (float), not grid or tile positions (int). To create a more natural effect, the random directions are similar in a period of time, so no abrupt change of direction occurs.

Is there a way to make entities avoid some tile types, or 'Tiled' tile properties, without losing the "wander" behaviour? I mean, choose random directions that do not reach these type of tiles?

\$\endgroup\$
  • 1
    \$\begingroup\$ if about to step on obstacle, re-roll move \$\endgroup\$ – ratchet freak Dec 16 '14 at 23:52
2
\$\begingroup\$

At some point during your entity logic, you'll have computed the random destination of the entity.

Before moving the entity there, check the type of tile that exists at that location. If the type is not desirable, abort the move, or try to generate a new random destination.

Often this check is encapsulated in a method on the tile object or the entity object called isPassable or isWalkable or similar, which can make the decision based on various criteria (such as "does this entity have a special ability that would let it walk on lava?" or whatnot).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.