I am completely new to Unity 2D and need some pointer.
I am making a turret defense game where the waves of units do not follow certain path. They spawn in the outer boundary in random locations and start walking towards the main building. On the way towards the main building, they try to destroy any turrets they come across in their path.
I have to have a way to make units walk towards attackable building while walking around any obstacles like rocks and stuff. What should I look into in Unity to achieve this? I heard of NavMesh in 3D but not sure about 2D. Ideally I do not want to use A*Pathfinding algo if Unity provides some solution out of the box.
The only built-in system in Unity is NavMesh.
And if you don’t want to touch A*, maybe you could create your own collision avoidance system, if not real path finding? Make enemies move to their left/or right if they detect an obstacle in front of them etc. This leads to of course many special cases where they might get trapped…
So even for the 2D game there is a way to do NavMesh where I indicate in Unity Editor “these parts should be avoided” with some kind of visual shading to tell the built in path finder? If I do this, does coding become a lot easier? Basically I say “walk towards this coordinate” in C# and Unity will find the appropriate path for me and start moving the GameObject?
You can always use raycasting or line casting to detect objects and make the enemies change direction. You can also use it detect your turrets nearby and make them walk towards them when within range to do so. Here’s a decent video that will show you how the AI code would work: