My enemy combatant seems to prefer the wrong axis for Grid Move. Here is a picture to illustrate:

image

In the first example the player with a move range of 4 moves to the edge. The enemy with a move range of 3 then moves toward the edge. This is a problem. If the player then moves back to the left, the enemy again (and always) mirrors his action, and we have a stalemate.

In the second example, the enemy now has a move range of 4 just like the player. Instead of moving to the edge, the enemy now moves 3 to the right and 1 down—good! But it would be better if it moved 3 down and 1 right.

I tried to reproduce this with the 2D Grid Battle RPG tutorial, since my enemy Grid Move schematic is basically identical, except that it uses 3D—so, XZ horizontal plane instead of XY, and Character Controller to move instead of Rigidbody 2D...but the problem did not appear in the Forest Battle scene. The AI there was much better at moving across the field and cornering the player. So, I have to ask for your guidance. The link to my project that I sent you fairly recently would probably still work if you have need of it again for testing. Thanks for your attention.
  • When did you send me the project?
    I usually don't keep them around when I'm done with checking it out, so you'll probably need to resend it.

    The grid move schematic has nothing to do with this, since it just follows the found path. The pathfinding happens before, and e.g. moving 3 right 1 down or 3 down and 1 right put the combatant on a cell that's the same distance away from the player in your example. So, both are valid paths, but one was simply found first and the other didn't have any benefit over it.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited December 2022
    It was a month ago. I've just sent you an updated link.

    Based on what you said, I found I can manipulate the AI default pathfinding choice by simply changing spawn positions. In the example image, the spawn locations relative to the battle grid are: Enemy X+ / Player X-. This produces the worst result, as already described. Here are a couple other results:

    Enemy Z+ / Player Z-: When the player runs to the corner, the enemy also runs to the corner, but on the next turn it will run straight down the field toward the player.

    Enemy Z- / Player Z+: Perfect result: Enemy runs straight down toward the player and corners him in just 2 moves. However, if the enemy is then lured to an Enemy X+ / Player X- position, it will resume the undesired pathfinding behavior. But, at least now I have a way to guarantee the enemy will initially approach the player instead of dallying around in the backfield.
    Post edited by Scyra on
  • I'll look into your project - though, technically, both are moving the same distance and have the same distance to the target. The pathfinding simply starts looking into a direction and will find a certain path first.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thanks for looking into it. If nothing can be done, I'll find ways to work around it.
Sign In or Register to comment.