Mindustry

Mindustry

37 ratings
Unit Hunter Logic
   
Award
Favorite
Favorited
Unfavorite
Tags: schematic
File Size
Posted
Updated
480.000 B
13 Jan, 2021 @ 6:11am
15 Feb, 2021 @ 7:47am
4 Change Notes ( view )

Subscribe to download
Unit Hunter Logic

Description
Tells all units of one type to follow and kill visible enemies.
If no enemy is visible, the units will return to a rally point, or to the player core if no rally point is found.

Enemy units count as visible if they are either:
  • in range of the controlled unit
  • in range of a tower

Since a lot of units are nearly blind, the processor allows to use watch towers to share information with your units.

To connect a tower to your processor, simply click on the processor and than click on a turret in range of the processor, as you can see in the image above.
Anything the turret sees will also be seen by your units.

The turrets you use as watch tower dont need to be supplied with ammo or power to be able to detect enemy units.
Recommended turret types for watch tower would be the Hail (high range early game tower) or the Foreshadow (high range late game tower)

Customization:
Change controlled Unit Type in the 1st command of the processor (Default: Flare)
Change max amount of used watch towers in the 2nd command (Default: 8)
Change approach range proportion of your units in the 3rd command (your units will follow the enemy up to that proportion of their shooting range (value between 0 and 1 (between no distance and full shooting range))) (the lower this value the easier it will be for a unit to follow an enemy)

Disclaimer:
The logic processor I m using here is inexpensive and slow, with this one units will have trouble to track fast moving enemies because the processor updates too slow.
You will have a lot better performance if you build a "Hyper Processor" (last tier processor that needs cryo fluid), and copy the code from my lower tier "Logic Processor" into it.

----------------------------------------------

Latest Updates:
- type of the watch towers is no longer hard coded
(just link anything to the processor and if it can detect enemies, it will)
- units approach distance is now a parameter editable in the first few lines
- amount of turrets is now a parameter editable in the first few lines
- units targeting now enemies instead of enemy positions
- replaced approach distance with unit range proportion
16 Comments
RedGoat 8 Jun, 2024 @ 4:27pm 
trying to use this and the return to core behaviour makes the logic useless when i want my units to attack at the frontlines, if the author wont update it can anyone modify the script and post an updated version? i'd do it myself if i knew how to code
TheNightglow  [author] 21 Oct, 2023 @ 6:25am 
Yea you are right @Kareekoe
I have not looked at this in a while but seems like the Rally Points were removed from the game
you could do the same I do for the watch-tower turret selection, and simply see if the selected object is not a turret, if its not a turret use it as rally point

then the user would just need to mark a non-turret object the same way they can mark turrets as watch-towers right now

not sure when I ll be able to adjust the code tho, have not looked at mindustry in quite a while^^
Kareekoe 21 Oct, 2023 @ 5:08am 
Seems this logic's rally point function might have been made for when the command center block was a thing back in Version 6.0 and stopped working after the command center block was removed when Version 7.0 was released.

Wonder if there's a way to fix this logic's rally point function to work similar or the same to how it probably did when the command center block existed, maybe there's a way to have the logic make the units hang out around the unit production building rally point?
Kareekoe 21 Oct, 2023 @ 4:46am 
No idea how to set up a rally point.
Seems that the rally point of the unit production buildings don't count as the rally point for the logic.
Veldie 7 Feb, 2023 @ 5:09am 
How do i set up a rally point?
[TC] Toaster Oven 8 Oct, 2021 @ 2:06pm 
I posted it as an issue on Github as this indeed seems like a strange bug:
https://github.com/Anuken/Mindustry/issues/6123

Maybe head over, give it a read, and add your side of the story to the issue?
The more specific information the better.
TheNightglow  [author] 8 Oct, 2021 @ 8:02am 
thats quite odd... it does not seem like there is anything wrong with your code, so i checked mine and my Unit Hunter Processesor also no longer works in the way it should... I know it used to take all linked turrets, but right now it does the same for my code as it does for yours
I feel like the devs changed something and I havent updated my code accordingly (havent kept this mod up to date since February), or this might simply be just a bug^^

in any way, this error is not just with your code in the pastebin but also with mine here in the workshop
[TC] Toaster Oven 7 Oct, 2021 @ 10:07am 
Nice, I recently modified it to work with another processor (and a few other small changes), but for some reason the code seems to only detect the first building I link. Individually linking to only one turret always works, but when there are multiple----some turrets are completely ignored (wTT always comes out as null---when they shouldn't [enemies within linked turret range]). Also, in that situation, the first turret linked ever (during session), seems to get priority while the others ignored, any ideas?

mlog code (paste in VS code or import into a Mindustry processor for easier reading):
https://pastebin.com/0nERbKdi
Pokeking 4 Jun, 2021 @ 2:37am 
Now flares and minkes won't let targets just walk on by!
TheNightglow  [author] 15 Feb, 2021 @ 7:54am 
thx, I updated the schematic to use the unit range now, tho instead of

op sub minRange range 1

I do a multiplication with a proportion value, because if the units only approach up to their shooting range, they wont be able to follow the enemy (since the processors update slower then the enemy walk, the enemy can escape the field of fiew of the units otherwise)