How do you use tilemaps with LOS?

0 favourites
  • 9 posts
  • In a game I am making the players control ants who go to places that the player clicks. The ants die if they run into water and since the water flows around it would be pretty infuriating if they just suicide all the time. To try and remedy this I want to make it so that if an ant sees water too close to itself it will back off and regenerate its obstacle map. My problem is that LOS seems to pick up the origin point of the map instead of the position of individual tiles.

    Can LOS be used to 'see' individual tiles in the tile map?

    (As a side note if anyone has a better idea on how to do this I'd love to know)

    Here is a capx: ... sp=sharing

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You don't have any other solid objects, so the line of sight from an ant to water can't be blocked by any other object, is this correct?

    In this case you don't need LOS behavior, you can simply check if there is a water tile close to the ant.

    Use Water.PositionToTileX(ant.x), Water.PositionToTileY(ant.y) to get the tile the ant is on, and then check tiles around it.

  • If I check their angles then I guess I could compare the tile in front of them to check if it's got water on it. I'll give that a shot

  • Capx: ... sp=sharing

    This is kind of rough but I think this is what you were saying? I don't think this will work unless I make the tiles much smaller since the ants can't fit through gaps without stuttering a lot. The problem with that is that the might be too close to the water to actually avoid it at the point. The only other thing I could think of to get around that is to make the cell border size bigger but that would mean they would need at least two or three blocks clearance to move through an area

  • Ants are shuttering, because your algorithm is wrong. Ants detect water, stop, get wet, find new path, start moving, you set wet=0, they detect the same tile with water again, stop.... And this happening many times a second.

    You can try "On collision with water" instead.

    Also, why do you use Terrain array? The tilemap itself is like an array, and there are expressions to convert layout coordinates to tilemap coordinates and vice versa. So I think the array is just making things more complicated.

  • Well I just used the array since it's more or less the same as the tilemap and I mean I'll be honest I'm not entirely sure how else to do it, I need to reset the wet variable otherwise they won't try to find a new path the next time they hit water

  • Well, try "on collision with water".

    You can use an invisible circle sprite (with round collision polygon) for collision detection and pathfinding.

    And a smaller ant sprite (with very small collision polygon) pinned to it.

    When that circle sprite collides with water - regenerate obstacles, find new path.

    When ant sprite collides with water, kill it.

  • Well then it comes full circle to my issue of LOS not working with the tilemap in my original capx. LOS would serve the same purpose as an extra collision box pinned to the ants

  • But since LOS doesn't work, you can't use it. So the next best option is an invisible collision box

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)