How do I combine turnbased gridmovement and pathfinding

0 favourites
  • 7 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Hi,

    im currently working on a little roguelike/rpg game, movement is grid and turnbased, means if you or an npc walk 1 tile it costs 1 actionpoint.

    So that the NPCs dont run over obstacles like walls and trees i tryed building a simple pathfinding system, like "if way on x axis blocked "->"try walking 1 tile in y direction" and so on, but im running into problems, like when the NPC is standing in an dead end.

    does anyone know an easy algorythm for that problem?


    heres what i got so far, its not very clean but i hope readable, im trying to get it to work first and then clean up and optimize

    the events dont show every condition but there are basically three more for NPC.x>player.x and the same for y directions.

    The NPC always trys to first match the players x position and then y, and maybe that start is already wrong ^^

  • i think i found a solution, its called A Star or A* algorythm, i even found a plugin for it here on the forum!

    just in case somebody else got that problem!

    now i have to try it out

  • You can use the path finding behaviour It uses A* as well, just do a normal find path to X,Y, where the X, Y are the converted values from the tilemap. After that you shouldn't use the "move along path" action. Instead all the nodes for the object are stored, which you can use to make a movement system. Kind of the same way that you have don't it. Doing it that way it will automatically take obstacles into account and save you the time of having to make your own A*.

    When that is said, you should be aware that the path finding behaviour in C2 have some serious problems, when trying to find paths also it is not designed for this type of movement, so objects wont move directional when near obstacles, so you have to make a workaround for that as well. And also you can't make different units collide against different things, it doesn't work. And there are some more problems, that you will most likely run into at some point. So depending on your game design and your map design it might save you the time of making your own A* and just design around these bugs/problems. But you have to try it for yourself to see if it fits your game or not.

  • Thank you nimos100 !

    i tryed with the C2 pathfinding system but i have a feel its not good programmed, for instance often the npcs cant find a path though theres clearly more then one available and it can take awefully long to calculate a path.

    im using the AStar plugin of 00Rez. it works really good and fast! like you suggested i will only use it to calculate the path and then let the NPCs move along with theyre own gridmovement style.

    only downside on that plugin is that i cant use the tilemap as blocker, so i have to spawn sprites for every rock and tree i have on the map but surprisingly it doesnt have so much performance impact so far, maybe i can find a better/more efficient way to solve this.


  • Yeah I tried Rez Astar plugin as well, but only fast, but first impression is, that its definitely worth consider using compared to C2s. However haven't tried it that much so don't know regarding tilemap, or whether there is a workaround maybe. However did notice that it bugs with blockers, if you use the angle to rotate them. Then it can't figure out how to go around them correctly. So you have to rotate the actual image it seems. But overall It seems very fast and good I think.

  • why u dont just load different tilemaps for each object type , trees walls one tilemap and road onetilemap when player is moving and the path on road tilemap doesnt overlaps on the tile u want to move with obstacle tilemap u can move if it does just say action not possible or tell to find a diferent path depending on how u want your game to work, that the easy way of making it in my mind, use the graphics. if u dont use tilemaps dont have no ideea ... maybe try updating the path of path finding each action u do, so the engine calculates the obstacle before it moves the charachter

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • However did notice that it bugs with blockers, if you use the angle to rotate them. Then it can't figure out how to go around them correctly. So you have to rotate the actual image it seems. But overall It seems very fast and good I think.

    good to know! fortunately i dont need to rotate my blocking sprites so i think im good with 00rez's plugin.

    This is how it looks now, have to re-add the smooth movement

    currently im spawning a sprite for every tree on the map and its ok, performance wise, but i fear i might run into problems when adding NPCs that can ignore different terrain types but have to respect others like birds goin over water or trees but cant pass walls, ghosts that can pass walls but not water and so on. Im thinking of spawning a basic blocker object for normal humanoids that blocks trees, walls and water/pits and some other objects that only go for one special type like, trees and walls but not water for swimming NPCs and i fear the sprite count will go insane but we will see.

    i dont completely understand what you mean but basically the problem is 00rez plugin doesnt look if a tile is set or not, it just looks at the size and coordinates of the tilemap object so if i use it as a blocker the path is always blocked because its all over the gaming area.

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