Pathfinding and diagonals in tile/step based movement?

0 favourites
  • 5 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • So, I want my game to have 8-directional, tile-based movement, where each step is counted as part of a turn, and the characters move the length of a tile in a single movement. Think roguelikes like Tales of Maj'Eyal, or movement in tactical RPGs like Fire Emblem or the newer Shadowrun games.

    I've managed to do 4-direction tile & step based movement, and also partially finished the turn tracking aspect of it with variables.

    Unfortunately I'd REALLY like my characters to be able to move diagonally, and 8-directional movement behavior doesn't seem to play nice with tile/step movement.

    The other problem is my enemies need to be able to pathfind to the player in a tile-based environment, following the same rules as the player, and the pathfinding behavior also doesn't work nicely with tiles and steps.

    This seems like the kind of thing that someone would have solved already, though I know Construct isn't used as often to make this kind of game... searching through the forums I found nothing that helped me. Could anyone give me a hand with getting these types of movement working together?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • From the Manual entry on Tile Movement it doesn't seem like diagonals are currently possible:

    https://www.construct.net/en/make-games/manuals/construct-3/behavior-reference/tile-movement

    You could make your own tile based movement using tween though. It would allow for diagonals

  • From the Manual entry on Tile Movement it doesn't seem like diagonals are currently possible:

    https://www.construct.net/en/make-games/manuals/construct-3/behavior-reference/tile-movement

    You could make your own tile based movement using tween though. It would allow for diagonals

    Ah, that really sucks. It's odd that they wouldn't have that, given a lot of tile-based games nowadays allow for diagonal movement.

    I suppose I could try using tween though. How would you go about that? i did a bit of testing wrt moving the image itself and it uh, starting skipping around the map like a nutcase. moving 4+ tiles at a time.

  • This is one way to do it

    Give an object Tween behavior

    On any of the movement inputs,

    check if Object is NOT tweening with tag "move" (you want to make sure the object doesn't receive input while it's actually moving, otherwise it will tween while it's tweening, resulting in skips)

    If it's NOT already tweening with tag "move,"

    then use the Tween 2 properties action to set it's position like so:

    (this would be for a diagonal up and right movement)

    X: tilemap.snapx(object.x + 32)

    Y: tilemap.snapy(object.y - 32)

    tag: "move"

    Also set up an On Finished: tween tag "move" with the action

    set object position to

    X: tilemap.snapx(object.x)

    Y: tilemap.snapy(object.y)

    (just incase it ends up unaligned with the grid somehow, this will realign it)

  • Thanks! This isn't working exactly how I'd like (the image mask seems to snap to the lines of the grid, rather than within the tiles themselves..?) I think I might be able to tweak it to my liking. I'll let you know how it goes.

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