can pathfinding behave like TileMovement??

Not favoritedFavorited Favorited 0 favourites
  • 13 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • or can an NPC using pathfinding chase a player while only moving within a grid, like TileMovement?.

  • Yes, if you align the tilemap and configure the pathfinding grid properly. Also, disable diagonals in pathfinding, and use MoveTo behavior to move along the pathfinding path - it's more accurate.

  • my grid is 16*16 px., obstacles are a tileset with solid behavior, tilesets are also 16*16, characters are 16*16

    I am unsure of what you mean by aligning the tilemap and configuring the pathfinding grid.

    currently these are the pathfinding settings:

  • Try Cell border=-1

    Here is a demo:

    dropbox.com/scl/fi/fb9xopeimo4ht4mwbzu2q/PathfindingOnTilemap.c3p

  • THanks, that seems to sort out the movement, but now i have a strange behavior. it's as if the origin point of the npcs switches from being at top left, to center center. Or I don't know what is happening. It's as if their origin point, has to go through the center of each tile and when they reach the player they reach it at the players center, even though the origin of the player is also top left.

  • The easiest fix would be moving the origin point to the center for all objects.

    Alternatively, you will need to offset all path points by 16px. Say, find path to (NPC.X+16, NPC.Y+16), and when the path found - loop though all nodes and add 16px to them..

    Or use a separate invisible sprite with the origin point in the middle for pathfinding, and pin your NPCs to it.

  • Thank you for your previous suggestions. I've been testing my NPC movement logic. I'm using TileMovement within a "walk" event group (controlled by a global boolean) to simulate random roaming, and it produces the desired orderly 16-pixel movement without passing through solids.

    The "chase" event group, activated when the boolean is false , disables the 8 direction behavior, and uses the behavior you recommended for following the player. While this works perfectly in the example file you provided (with a single pathfinding call on load and a static player), I've observed significant issues in my project file when the player is controlled and the pathfinding is recalculated every 'n' seconds.

    Specifically, in my file only, once the chase events are active, the NPCs end up with a fractional tile position (e.g., 8 pixels in one tile and 8 in another). This breaks the 16-pixel grid alignment and allows them to move through solids. In your file I also observed that the pathfinding + move to combination seems to create similar issues if I add 8 direction behavior to the player and make frequent calls for pathfinding (necessary to locate a moving player).

    In both cases the behavior is a bit erratical and npcs can suddenly start overlapping solids. Crucially, this prevents them from returning to the correct TileMovement behavior when the boolean is set back to true since they don't move in 16 px increments and I suppose the game doesn't know how to handle this when the boolean is toggled, or I haven't provided a way for the game to remedy their location.

    It appears the dynamic, repeated pathfinding updates while the player is moving are the primary cause of this instability and the inability to resume normal walking.

    Which brings me back to my initial question. I don't need to just move within the grid, I need each movement to de done in 16 pixel increments with the NPC only being able to move again after each step is completely finished.

    I know how to conceptualize this but I definitely do not know how to implement it.

  • I adjusted the grid offset of tileMovement just for the npcs and that seemed to correct a number of things:

    Npcs no longer place themselves 8px and 8px between grid cells

    Npcs no longer go through solids.

    Npcs behave more predictably, following the grid when they chase.

    I also disable pathfinding and move to behavior when "walk" group is active

    this reduced the instances of npcs getting stuck in solids significantly

    what hasn't been solved:

    Npcs still randomly get stucK in 1px overlaps with solids occasionally, but can be "dislodged" by activating "chase" which makes them head towards the player.

    Npcs that get "trapped" in between 16px increments when chase gets deactivated, get paralyzed in place unless "dislodged" as mentioned in the previous case.

  • Looks like you are using a bunch of different movement behaviors - pathfinding, tile movement, even 8direction? It will be difficult to make them all work correctly on a grid.

    I would keep Pathfinding and MoveTo, and get rid of the others. MoveTo is pretty versatile and works well on a grid. You can use it instead of the TileMovement, just check for collisions with events.

  • I am, just not all at the same time. When walk group is enabled, only 8 direction is enabled. When chase group is enabled, only pathfinding and move to are enabled.

    I initially used 8 direction because I am going for a specific look for the movement. Like an old dragon quest game.

    I would definitely switch to pathfinding and move to behaviors exclusively if I can somehow manage to make it work in 16 px increments, to simulate the way 8 direction movement looks. 8 direction is more straight forward regarding collisions.

  • I would definitely switch to pathfinding and move to behaviors exclusively if I can somehow manage to make it work in 16 px increments, to simulate the way 8 direction movement looks.

    Did you mean TileMovement? 8direction doesn't move in increments, and it's a poor choice for a tile-based game, because you want your objects to always snap to the center of the tile.

    MoveTo can be used on a grid:

    "Move to self.x+16" will move 1 tile to the right.

    "Move to self.x+16" followed by "Move to self.y-16" with "add waypoint" option will move 1 tile right and then 1 tile up. But you will need to check for wall collisions with events.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Dang, yes you are right, i don't know why I typed 8 direction. Yes, i meant tileMovement

    also , i must be doing something wrong because in the layout editor, if my sprite has the origin point at "center","center", the sprite snaps to the intersection of 4 tiles at the sprite's center. But if i place it on any of the corners, my 16px character sits correctly inside the 16*16 tiles.

    I think i need to read the manual again to refresh my memory about that.

    I will try what you suggest, because if i manage to make it work, that will simplify my events a lot. Thank you.

  • By default, the TileMovement behavior expects the image point to be at the top-left corner, while Pathfinding works best with the image point in the center. I believe if you set the image point to the center and set the grid offsets in the TileMovement behavior to 8px, both behaviors should work correctly.

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