AI walks X steps towards Player? (Tile Movement or Manual?)

0 favourites
  • 6 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Hi All,

    I have a grid split to many 32x32 cubes (quick background).

    I made the PLAYER to walk 32x32 (one step at the time) using the Tile Movement Behavior, so far so good!

    Since my prototype is a turn based style of game: Basically each character can walk X steps on the board.

    For the player it was very easy to setup, but for the Enemy I didn't start since I'm not sure what's the most simple way to do so.

    So, after failed tries with Path finding which always sliding and easing-in and out, I liked the Tile Movement best and I want to use it for the Enemy AI.


    If I set the same parameters for the ENEMY AI using Tile Movement 32x32 Grid, I wonder how I do these:

    1 - How do I make the Enemy to walk 32x32 but consider not just the X which is easy, but also the Y. How can I make the ENEMY to ALWAYS LOOK for the player and go in his direction, again based on the 32X32 Tile Movement.

    2 - If I put some 32x32 Solid obstacles on the board, how can I make the ENEMY AI understand manually that "THIS BLOCK is an obstacle" so CHOOSE Y (up or down) if one is ALSO an obstacle, try the other option and only then do your X Tile Movement based on 32x32 each step.

    Basically it's a manually path finding but not complex as the actual Path Finding behavior which I don't want to use, I want to make it manually as explained on #2 above.

    I want to limit every character (PLAYER or ENEMY) have 1 step for starting, later I will limit their steps but the test is very important to see if it works so they won't walk all they want.

    HELP or Advice will be very appreciated:

    I'm afraid I'm not good with loops and complicated stuff like this, but if this is possible to accomplish and you can think of a way or even better: SHARE an example file based on 32x32 grid it will be very helpful!

    Thanks ahead and have a wonderful weekend! :)

  • Some quick general tips, I don't know how you have your existing system set up exactly...

    You can use the pathfinder behavior to find the path, together with the tile movement to do the actual movement.

    Grid systems are in essence rounding to the nearest x/y on the grid, a translated coordinate system.

    Set the pathfinding behavior with a cell size similar to your grid. You can then access the pathfinding node coordinates, and round/translate them to fit in your own grid system.

    With the nodes in hand, you'll need to handle the movement steps manually - don't use pathfinding's move along path action. I don't believe the pathfinding can give you a node per cell, you'll have to interpolate those yourselves. Basically you need to figure out a way to describe each step between two nodes. For example, you start at 1,5 and need to go to 3,9. There's a few ways to go on a grid system. You can go right first then down, down first then right, or a mix of both by figuring out the slope.

    It might be simpler for you though since it sounds like you're only taking one step at a time, so you only have to get the next step. If you have your destination node, you know if its above or below, left or right of your current position. Pick one up/down or left/right, test if there is an obstacle with tile movement's can move to position, then move. Repeat with a new pathfinding step for the next move.

  • Thanks for sharing your advice and trying to help! oosyrag

    unfortunately it is probably too confusing for me to accomplish as I'm still learning and experimenting.

    This is why I didn't use Pathfinding earlier... as I tried to follow your advice which make sense combine with the Tile Movement (which is VERY easy compare to the Pathfinding Behavior) things makes me more confused.

    So I've attached a VERY SIMPLISTIC Layout you can see what I'm trying to do visually since it's GRID based 32x32 but I removed ANYTHING that is not related to the enemy pathfinding step (which is not exist yet), just to keep the file clean as possible.

    For now, the way to test it is to place manually the player on different places on the grid but of course there is no Enemy AI at all now, I'm just thinking how to test it without adding player movement to make the code clean as possible to focus on the Enemy AI first.

    If you, or anyone else can help me make it with Comments inside the Even Sheet explain what each event / action does I'll probably be able to understand, since my mission is NOT to let somebody do this for me, but to LEARN from examples, this is why I made this starting-point file.

    I believe that combining the Path Finding + Tile Movement behaviors is what I'm first stuck with.

    It is important for me that the Pathfinding won't do weird smooth sliding movements above or behind sprites but keep the Tile Movement priority to how things are moving around the grid board.

    Thanks ahead!

    Download: Clean Start-Point File


    Here is my attempt to combine guessing Tile Movement but it's super confusing, I can use "choose" if I'll put the simulation directions but it's still a guess for the Enemy AI, probably the wrong way to do this.

    Download: Failed Enemy AI Pathfinding + Tile Movement

  • Here's a pretty straightforward solution, for one step at a time at least.

  • Thanks for sharing this code oosyrag! :) with the PathNode sprite you've added it looks much more visually and easy to understated the path calculation result on the layout, very cool!

    Unfortunately, I'm looking at it and I see these overwhelming parameters inside the System on the Repeat loop and I'm even more confused to be honest it's probably not on my level to use Pathfinding.

    Alternative Solution (without Pathfinding):

    I wonder if there is an alternative to something more manually, based on the idea of the way people use to make the a weapon or target "LOOK AT" the mouse X & Y all the time then SHOOT to it's direction.

    So my idea is to make every tick (always) that the ENEMY will "LOOK AT" the Player position on the grid.

    Then when click to END YOUR TURN, it will go on that direction based on the 32x32 grid probably with the Tile Movement simulation.

    Sure, this won't solve how to handle the Solids... but before that, how do I make the enemy to "LOOK AT" the Player's position every tick, and do 1 step on the X (for start) towards the player when ending the turn. IDEAS Anyone ?

    I think this could be the basic enemy's movement mechanic, more manual and not accurate but it should work in theory. I just don't know how to begin with the above.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You should learn how to use expressions or you won't get very far in anything. The ones I used are



    These mean the X and Y coordinates of the first/next pathfinding node. The number is which node because there can be multiple.

    Angle (x1, y1, x2, y2) will get you the angle between two sets of coordinates.

    And loopindex is simply the number of times the loop has repeated. The first time it will be 0, then 1, then 2, ect. This is how I spawn every node with one loop.

    Pathfinding is useful so you have a way to avoid obstacles and go the right direction.

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