How do I force enemies to walk using pathfinding with tile movement?

0 favourites
  • 11 posts
From the Asset Store
Each tile 64 by 64 pixels - Ultimate Tile Set for your awesome games
  • Hi everyone,

    Imagine a classic Roguelike game such as Stoneshard for example; you move on a tile by tile basis and your enemies do the same.

    I am trying to simulate the same effect; having enemies in my game to pathfind their way to the player but moving based on tiles rather than fluid movement.

    The way I did it so far is to add both the Pathfinder and Tile Movement behavior to my enemy. But the results are really, really slow and off. Like sometimes the enemy would go far away from the player before starting to move towards them.

    Here is a GIF of what I mean by slow

    https://i.imgur.com/k7Fymhj.gif

    Originally I set my cell size to 16 (since I am planning to use 16x16 tilesets as seen from the sprites I am using. But that was a nightmare as the enemy would zigzag their way towards the bottom of the layout before starting to move upwards towards the player and it was much slower than what you're seeing here.

    Here is a screenshot of my current setup for both behaviours:

    https://i.imgur.com/tDNcZ1C.png

    Any ideas what I can do to achieve this?

    Side question; any idea how to setup this same behaviour but in a turn based system? Right now things are moving in real time. Any hints how I achieve turn based pathfinding and tile based movement for enemies?

  • There is no reason to use pathfinding with tile movement for the basic movement. You would use only the tile movement behaviour and move to a tile based on grid ID. When you move you have the choice to animate so the unit walks to that tile.

    Interesting you mention tile based movement in turn based setting, I am making a similar prototype right now. My approach was to add the units into an array for turns and pick the top one as the current turn. Then you move with the actions, chop it from the array and the next person moves up for their turn.

  • There is no reason to use pathfinding with tile movement for the basic movement. You would use only the tile movement behaviour and move to a tile based on grid ID. When you move you have the choice to animate so the unit walks to that tile.

    I am guessing in this case, I have to move the enemy manually to reach the player, right? Like check the direction (where the player is) then move based on that?

    I was hoping to avoid this to be honest and have pathfinding deal with it so I don't have to implement custom movement for every single enemy movement type I had; basically leaving complex movement to me custom making them and simple "move to reach enemy" would be pathfinding.

    Interesting you mention tile based movement in turn based setting, I am making a similar prototype right now. My approach was to add the units into an array for turns and pick the top one as the current turn. Then you move with the actions, chop it from the array and the next person moves up for their turn.

    I think this method may not work for me due to having attack speed and that affecting turns. But it could be mitigated with action count. Not sure. Basically I wanted to simulate attack speed = having more turns. But it could be that attack speed = more actions per turn and turn order/speed is the same regardless of your stats.

    Thing is, how do you "stop" the world and everything in it when it isn't their turn. If I use the pathfinding behaviour how do I tell pathfinding to move only one tile per turn? Or is this why you said I should forgo pathfinding?

  • Kinda depends on the exact gameplay. You say you don't want to build the move mechanic but pathfinding is demonstrating its own problems. When I look at that game you referenced you can click on a tile and move to it. When you use pathfinding to move about you are not really using tile movement, it's one or the other. If you pathfind to a tile this is the same as using move to tile with tile movement. I don't know what these complex movements are for enemies but I'm sure it is doable. As for the turns, my characters have haste which puts them at the top of the list. If they can attack twice you can add them into the array twice, or like you said within the same turn give them 2 actions and track this with a variable.

  • Kinda depends on the exact gameplay. You say you don't want to build the move mechanic but pathfinding is demonstrating its own problems. When I look at that game you referenced you can click on a tile and move to it.

    That is out of combat. In combat, you move tile by tile like any roguelike.

    When you use pathfinding to move about you are not really using tile movement, it's one or the other. If you pathfind to a tile this is the same as using move to tile with tile movement.

    I am not sure I understand what you're saying. The first sentence makes it so I can't use both behaviours at the same time. The second one makes me think that Tile Movement has some sort of pathfinding embedded? I am not exactly following what you're saying on the second sentence.

    As for the turns, my characters have haste which puts them at the top of the list. If they can attack twice you can add them into the array twice, or like you said within the same turn give them 2 actions and track this with a variable.

    How are you implementing the notion of a turn? Is it just a bool you flip? Or is that by pressing "End Turn" button and for enemies you make sure that any decision is taken is followed by a "End Turn" button internally?

  • I am just saying that tile movement move to tile is enough for that kind of game. To pathfind to a tile is the same thing but you end up with the problems you mentioned like sluggish movement or maybe it can't find a path, in my opinion less reliable than the tile movement which is just move to a given tile.

    Yeah pretty much, it grabs the name of the person at array(1) so it's their turn. They are set to active so it's obvious and you can use their actions. If it's an enemy I run their turn through a function, send their name through and they perform attacks or logic based on that. In the actual game world it picks the sprite to move based on the matching name. At the end of the turn I run some clean up logic and then move the next unit up in the list.

  • I am just saying that tile movement move to tile is enough for that kind of game. To pathfind to a tile is the same thing but you end up with the problems you mentioned like sluggish movement or maybe it can't find a path, in my opinion less reliable than the tile movement which is just move to a given tile.

    What is this Tile Movement move to tile is enough? I can't find that action at all. Is this a custom plugin or add-on?

  • Set grid position (animate) and the X,Y are co-ords in the tile grid

  • Set grid position (animate) and the X,Y are co-ords in the tile grid

    I didn't know that this action is used in this way. Thanks. Though how can I access the grid coordinates or turn X and Y of an object into grid coordinates?

    In the X I typed "Enemy.TileMovement." and I couldn't see anything that would allow me to do that calculation. Do I just place in the player's X and Y instead?

  • It's enemy.tilemovement.gridx. The tile movement has its own grid. If you set a sprite to grid position 0,0 you can work out where the grid is.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's enemy.tilemovement.gridx. The tile movement has its own grid. If you set a sprite to grid position 0,0 you can work out where the grid is.

    Ah, OK, I see. Right, get the player's grid's location and provide it to the enemy. Gotcha. Thank you very much!

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