Account for enemies with singlenodeblocker and traversalmodifiers

Hi there,

I have a problem with what I’m trying to achieve. I currently have my grid set up in the hexagonal grid layout. Movement is sorted but when it comes to calculating the singlenodeblockers and traversal it blocks the node which the enemies stand on, so I can’t generate a node to click on.

If I don’t use the single node blocker in the calculations for the enemies, I end up walking around them BUT because it is moving around them, I end up being able to move further as if the enemy wasn’t in the way.

Is there a way to allow enemies to be calculated in the path so that a node can be generated for them, BUT allow them to be avoided in the path. I can’t seem to get it to mix together.


From these images you can see me generating the nodes around the nodes in the path and all areas around up to a certain range, but with the traversal modifier being blocked at position by the enemies. They aren’t calculated and thus get ignored.

Thank you


You seem to already be including the traversal provider in all cases. Do you think you could post a screenshot of the issue so I can understand it better?

So as you can see in the image above, I have 6 movement points. This is currently without it in the code. so the traversal modifier isn’t being accounted for in the path. Yet the player will move around the enemy.
The path calculation will still say it is 6 movement points to the blue line, yet it’s 7.
The red line it the point it should be showing.
BUT now with the traversal modifier being accounted for, which I reneabled in code, the single line. The enemy becomes an “obstacle” and not part of the calculations, so I’m wondering how can I get around this? Do I do 2 seperate calculations one with and one without traversal modifiers accounted for?

I want a way which I can treat the enemies as something I can’t move through in the calculations. because the movement will move me around the enemy. but the calculation treats it as if it goes through. Is there a better way to search for all available nodes within a range?

Also the enemy no longer gets generated a hexagon because they aren’t included in the calculation.

Ah I see.
Essentially you want the enemies to be valid end nodes, but they should not be possible to pass through.
This is not possible in the current architecture unfortunately, so I think you’ll have to do something like this:

  1. Do a search that treats enemies as obstacles
  2. Do a second search that also treats enemies as obstacles, but searches with 1 movement point less.
    2b. With the second search, iterate through all nodes and for each node iterate through its neighbours (GridNode.GetNeighbourInDirection or GridNode.GetConnections). If the neighbour node is occupied by an enemy then add it to the list of possible targets.
  3. When you search for a path to an enemy, treat all enemies as obstacles except the one you are targeting.

What happens if there are multiple enemies, lets say you have 2 enemies stood next to eachother, how do you account for multiple enemies. if the path just goes straight through them.

I didn’t think this capability was in this as I found no documentation about it. Do you reckon this is something you’ll add in future? It kind of seems like an essential part of turn based strategies XD being able to target enemies :smiley:

The current way I had enemies as end nodes was to simply go to the position one before the end of the path, and that way you land on the space before them.but trying to figure this out is really difficult.

Is there a way to make it then so the player walks through the enemies instead? I’ll try and adapt to a different method if this one isn’t implemented or part of the architecture.

The main reason I noticed this was when the AI I set up tried moving towards the player, they actually walked into eachothers node on a few occassions, which led me down a rabbit whole of figuring out why I the AI weren’t using traversal modifiers and then the player was actually walking 1 to many steps

I do hope this is something you’d consider implementing as it seems sort of a vital part of RTS games. For now I’ll treat them like obstacles and generate a node below their feet on a second search