Move anything in a isometric map using something like A*

0 favourites
  • 5 posts
From the Asset Store
A template which allows you to customise the controls of your game.
  • Hey guys,

    I really need help over here. I have a isometric map like this:

    Example:

    I need calc the better path (step by step), from 0,2 position -> to 2,1

    One of this paths will be: 0,2(start) - 1,2 - 2,2 - 2,1(end)

    My problem a question:

    Anyone already do something like that? I start looking some implementation from A* algorithm to solve this , but I'm not completely sure it will work on C2.

    The c2pathfing plugin can't help me on this =(

    I already know the distance cost of each tile using some math ( |X-dX|+|Y-dY| = distance cost) :

    I think i can find a logical solution , but I'm afraid of messing up the in C2 implementation.

    Has anyone ever done something like this?

    Sorry for the poor english.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I use something similar in my game and ran into a lot of problems with it as well. You can however use the pathfinding in C2, you just have to use it as a non optimized pathfinding tool that will just give you the basic path from A to B. It have quite a few problems with tilemaps, which you will have to correct manually afterwards.

    The way I use it in my game is like this:

    1. Enemy acquire a target

    2. Find the nearest empty tile near the target.

    3. Find path to this tile.

    4. Store all the nodes which it have found.

    5. Since it have problems moving diagonal around other units (Big problem when using tilemaps). I correct the path everytime a unit moves to make up for this.

    6. As this doesn't solve all problems and the pathfinding ignore some collisions for some reason. I will in case step 5 doesn't solve it, make it find a path again. Which will make it start from step 1 once again, but from its current position.

    But that will eventually get the unit to the target.

    So you should be able to do the same in your game as I have in my game. The way you do it is to check the node after the one its currently moving towards. If this node is next to the current one you remove the current node and instead let it move to the next one.

    Using your example:

    0: 0,2

    1: 1,2

    2: 2,2

    3: 2,1

    Lets assume the unit is standing at 0, 2 then you test:

    Value of

    node(Unit position).X + 1 = node(1).X

    and value of

    node(Unit position).Y = node(1).Y are true

    Since that's the case you know that the unit is moving from left -> right

    So now you have to check if the next node again is above or below node(1)

    So you do another check:

    Value of

    node(Unit position).X + 1 = node(2).X

    and value of

    node(Unit position).Y - 1 = node(2).Y are true

    If that's the case you know there are another node above node(1)

    And for the bottom:

    Value of

    node(Unit position).X + 1 = node(2).X

    and value of

    node(Unit position).Y + 1 = node(2).Y are true

    Would be a node below node(1)

    Since none of these are true you do nothing an let the unit move along the path.

    So now the unit is at (1.2) and then you do it again.

    Value of

    node(Unit position).X + 1 = node(1).X

    and value of

    node(Unit position).Y = node(1).Y are true

    Again this is true indicating that the unit is still moving from left -> right

    So we check to see if there is another node above node(1):

    Value of

    node(Unit position).X + 1 = node(2).X

    and value of

    node(Unit position).Y - 1 = node(2).Y are true

    Which there are in this case (2,1)

    So you remove node(1) from your list, so instead of the unit moving to (2,2) which it would normally do, it will now move from tile(1,2) -> (2,1)

    And you make something like that for all directions. Whether that will solve all your problems I doubt and you most likely have to do as I showed in the above approach.

  • Wow. Thank you nimos100 . I'll try something like your suggestion.

    Looking for how implement A* in c2, i found this:

    Maybe can be healpful to you too

  • C2 does already use A* as far as I know. The problem is just that its very limited in its implementation, so its more or less only useful for simply finding a path from A to B. The moment you need it to do something more advance it quickly falls apart resulting in weird problems. That's why you can use it to find a path and then you add "Patchwork" to fix the things that fails.

    So think its a bit of trade off, whether you want to make your own which would give you a lot of control like setting the G score make sure it can move diagonal passed other units correctly or whether you use C2s pathfinding as basis and correct the things that doesn't work well. What takes the longest time and is the most complicated im not certain off.

    But as I see it C2 pathfinding is mainly aimed towards RTS games, where it doesn't have to be all that precise and it doesn't matter to much if units move correctly passed each other, which will give it better performance for such games . But for tilebased games these errors become really obvious and will need to be corrected.

    However if you fancy making your own, this is a good page to start I think.

    http://www.policyalmanac.org/games/aStarTutorial.htm

  • It is possible to do. You should take a look at this indepth tutorial on how to do A* pathfinding. Really helped me out.

    http://www.raywenderlich.com/4946/intro ... athfinding

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