Can place towers on Start and End coordinates

Hi there,

Not sure if this is a bug that anyone else has had, or if Gary came across it or mentioned it (I’ve now completed this course and don’t remember it being talked about).

When I place towers on an enemy path, it re-calculates the path and re-routes the enemy no problem. My issue is, I can place a tower on the Start and End coordinates. Nothing breaks, and the pathfinding still works, it just looks a bit funky having the enemy go through the tower.

Importantly, I can’t place a tower on a path node if it would block the path, so that is working properly. I’ve gone through all the source code and compared to mine, and can’t see any differences.

I can also still place a tower on these nodes if i make their ‘isPlaceable’ flag false.

Any ideas here?

1 Like

Hi,

Welcome to our community! :slight_smile:

That’s a very good question. For the starting node, I suspect that the problems are caused by the first two lines in the BreadthFirstSearch method:

startNode.isWalkable = true;
destinationNode.isWalkable = true;

We do not check whether they are walkable. We just hard-code their value. If that makes sense, feel free to develop a solution yourself.

I would ‘exclude’ the start and the destination node from the pathfinding like this:

// in WillBlockPath()
if (coordinates == startNode || coordinates == destinationNode) { return true; }

Did this help? :slight_smile:


See also:

1 Like

Thanks Nina.

if ((coordinates == _startCoordinates) || (coordinates == _destinationCoordinates)) { return true; }

Using coordinates and startNode / destinationNode gave me an error of not allowing the operand == with Vector2Int and Node.

It works so far and I don’t seem to have any problems stemming from it.

Thank you for the assistance :slight_smile:

1 Like

Of what type are, for example, coordinates and _startCoordinates? Of course, they need to be of the same type. I didn’t that take into consideration when I typed the suggestions in my previous answer and falsely assumed that startNode was the coordinates of the startNode. My bad.

In your solution, if one of them is a Node object, you have to access its coordinates variable and compare that value with the Vector2Int value. That should fix the compiler error.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms