Can't get BlockManager to work

Hi,
I’m trying to make a 2D turn based game, where I want the enemies to avoid eachother, but obviously not themselves.
Looking at the documentation, this page is pretty much exactly what I’m after (I think): https://arongranberg.com/astar/docs/turnbased.html

Unfortunately, the page feels a little incomplete, or maybe it’s just because I don’t have the pro-examples.
So, a couple of questions:

  1. The example calls blocker.BlockAtCurrentPosition() in Start(), does this keep track of the objects position, or should I call it again, every time the object (enemy) has moved?
  2. From what I gather, the BlockManager.TraversalProvider is what I need to then make the enemies do the avoid. It takes in a List<SingleNodeBlocker> as obstacles. In the example, this is just a public property, how does this get populated? Is that something I need to do myself?

I feel like some points are missing in that article. Like it’s an incomplete example. This could, of course, just be due to my lack of knowledge on this package.
Am I missing something else? Any real examples I can check out, anywhere?

Hey,

For the most basic implementation you can just follow all the steps in the Blocking Nodes part of the Turnbased document.

You are correct that you have to update the BlockAtCurrentPosition(); whenever the object has moved.

private SingleNodeBlocker blocker;
    
    private void Start()
    {
        blocker = GetComponent<SingleNodeBlocker>();
    }

    public void HasMoved () {
        if(blocker != null)
            blocker.BlockAtCurrentPosition();
    }

You can add multiple objects to the obstacle list. Like so:

2 Likes

Awesome, thanks. I think I got it working now.

1 Like