Having Problem with pathFinding after broadcast messages

Lecture 143

hi, I am avik , first, my project was working fine till the lecture - script execution order, but when it started lecture broadcast message and made some changes to the script as instructed my project broke and I am having many issues with pathfinding and tower placement. the 1st problem is that all the enemies go directly to the end position after one enemy without following any path.

I have done the script execution order and the shifting of code from awake to breatFirstSearch

before doing broadCast messages it was working fine without any problem and this was also fixed in that lecture but now it is not working. I tried comparing my code of all scripts to the instructor one but nothing worked.

the second problem is that I am not able to place towers when enemies don’t follow the path.

here is a video showing the problem

https://drive.google.com/file/d/1LOKTnabWE69PBy1z3a8PaSKHJb879P8e/view?usp=sharing

pls help me out with this as I don’t have any previous version of this project

link of project https://github.com/AvikYadav/towerDefence

Hi Avik,

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? Have you already rewatched the relevant videos at least one more time?

I’ve watched your video, and the first enemy seems to me following the path. The next enemy seems to fly straight to the end point without any reason. Try to figure out what causes the second enemy to follow a different path and if it is following a different path or if it’s ignoring the path. Have you already tried to add Debug.Logs to your code to see what is going on during runtime?

Hi @theplayer,
It looks like a similar problem to the one I was encountering at the end of the “Script Execution Order” lecture. However, I can see that you’ve made the required code changes to fix it.
This means that something else is going on with your project, but unfortunately I was unable to download and run it from the GitHub repo.

The general problem is that your enemy isn’t able to find a valid path from start to finish, so the only node in the returned path is the destination node. This is why it move straight to that point when it gets enabled.

To help narrow down the cause, try adding some debug logs to your BreathFirstSearch() method to check the walkable state of each node as the search progresses.
You may also want to try commenting out the line of code in Tile.cs that is responsible for blocking nodes, to see if that temporarily fixes the pathfinding issue.

This should hopefully help you narrow down the search for what’s causing the problem.

thank you, sir and ma’am, for your suggestion I found the problem that when the first enemy spawns and gets enabled he finds the valid path but the path still contains some tiles that are set to placeable = false. but then also the path include those tiles, what I found that is after the first enemy follows the path and gets disabled but when he is enabled again by our object pool then that path only contains the end coordinates, I am not able to find why there is only end coordinates but I will try to provide by project through drive

getting proper path at first, but if you focus on the last message you will note that the end coordinates are only coming again and again.


here 12,0 and 11,0 tiles are not placeable but the path still includes them

link for my project files - tower Defence - Google Drive

What is most likely happening is that your Tile script is changing the state of the start node in the time between the first and second enemy spawning (the first one basically just gets lucky with the timing).

In BuildPath() the destination node is added manually (before the while loop), which is why that’s the only one present in the path and the enemy heads straight there.

Did commenting out those lines in the Tile script temporarily fix the problem?

thank you sir, I was so silly that had turned is placeable of startTile to false and now it runs perfectly fine

2 Likes

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

Privacy & Terms