Tower Defense "first" targeting
Hello guys, basically my problem is this - In tower defense game (3d top down) I am trying to shoot the first enemy, thing is my enemies have various speeds for example there is a fighter that moves at the speed of 5 and then there is a scout that moves at the speed of 15. And my targeting works basically in two ways it detects collision add's enemies to the list and start's shooting until dead or out of collision radius (range) problem is if fighter enters the radius first (get's added to the list) and the scout enter's the radius and runs past the fighter tower keeps shooting at the fighter since he technically collided first. Tried to solve this by calculating distance between end point and the enemy, but problem happens if the map isn't just a straight line since the closest enemy can still be farthest away from the exit since the road goes up and down. I don't really need code example just general idea how it could be done since I am quite out of the ideas don't suggest A* algorithm.
Answer by justasxz · Mar 14, 2020 at 03:50 PM
Actually found the best solution myself. There is a thing called NavMesh inside Unity if anyone needs to solve this problem just click window at the top>Ai> Navigation from there just select your path and in new tab that opened navigation select object click navigation static checkmark and keep it on walkable then go back to Bake and click bake and it will create the path you can walk on and auto track the distance between destination (proper not straight vector but actual distance) of course you will need a script to set the destination it's quite simple attach nav mesh agent to your object that you want to follow the path attach a script to that object get component nav mesh agent and use function "Your Nav Mesh Agent Variable Here".SetDestination(your target destination) after that you can just use remainingdistance function for the distance.
Your answer
Follow this Question
Related Questions
Seemingly easy Targetting problem! 0 Answers
Script C# AITargeting for the Gem Mining minigame 2 Answers
transform.LookAt not looking at the target 0 Answers
Drag and Drop Targets 0 Answers