Page 1 of 1

[2.0.72] Turrets firing at targets they cannot hit [mods]

Posted: Sat Nov 08, 2025 1:43 am
by wtgibson
It seems the combination of "Krastorio 2 Spaced Out" and "HeroTurrets_Redux" creates turrets with weird range issues.
For context, as turrets kill more enemies they 'rank up' and get increased range.

I created a reproducing save with a gun turret firing at a worm in a particular position, which it is unable to hit.
The turret has a non-vanilla range value, and this appears to be the cause.
I expect that for any range value, the turret either fires (and has a nonzero chance to hit), or does not fire due to range.

Shooter: "hero-turret-3-for-gun-turret' at -4, -5

Code: Select all

/c local e=game.player.surface.find_entities_filtered{position={-4, -5}, name="hero-turret-3-for-gun-turret"}[1];game.print(serpent.line(e));
It's Rank: Sergeant

Target: small-worm-turret at 27, 12

Code: Select all

/c local e=game.player.surface.find_entities_filtered{position={27,12}}[1];game.print(serpent.line(e));
Comparing shooter to target:
Dist=35.36 Range=34.38 Target bbox={26.1 11.2}-{27.9 12.8}

Code: Select all

/c local surf=game.player.surface
local t=surf.find_entities_filtered{position={-4,-5}}[1]
local target=surf.find_entities_filtered{position={27,12}}[1]
if not (t and target) then game.print("Missing turret or target") return end
local dx=t.position.x-target.position.x
local dy=t.position.y-target.position.y
local dist=math.sqrt(dx*dx+dy*dy)
local range=t.prototype.attack_parameters.range
local bb=target.bounding_box
game.print(string.format("Dist=%.2f  Range=%.2f  Target bbox=(%.1f,%.1f)-(%.1f,%.1f)", dist, range, bb.left_top.x, bb.left_top.y, bb.right_bottom.x, bb.right_bottom.y))
Since the center-to-center distance is 35 and range is 34, I wouldn't have expected any firing.
However the closest corner 26.1, 11.2 is 30.1, 16.2 units away, which is 34.18 units, just within range by 0.2 units
bbox size: 1.8, 1.6


I have seen this behaviour in real games on asteroids, on nests, etc.
What is unusual about the replication save file is that the turret folds between each and every shot. In game, I have seen the turrets just full speed firing at targets and never hit them.

I have made other replication cases (not included since less interesting) where the turret takes several shots to kill the target, seemingly due to gun inaccuracy.

Oh!
Further testing shows that ranking up to 'General', 'Field Marshal' or 'Supreme Commander', cannot hit the target either, despite having more than enough range. Now the turret does not fold between shots.
Turrets with ranges: 34.38, 37.50, 38.75, 40.0 fire at and always miss target with center-center distance of 35.38.


I have tried replicating this with "HeroTurrets_Redux" but without "Krastorio 2 Spaced Out", but have been unable to find a replications case - the gun turret ranges are different here.
In "HeroTurrets_Redux" only ranges: 18, 20.3, 22.5, 24.8, 27.9, 28.8 (rounded in UI)
With both mods, range: 25, 28.1, 31.3, 34.38, 37.50, 38.75, 40.0

My only current hypothesis is that while the turret has the range, its accuracy falls so fast that the probability of hit goes to zero past range 35+.
If it is accuracy, can we get a minimum accuracy of 1% or something, so we don't end up in situations where turrets can waste infinite bullets pointlessly?


Testing instructions:
-Load save file for Sergeant turret. Observe sporadic firing.
-Pipette (Q) target and place ten within firing range. This will trigger a rank up, and upgrade the turret. Repeating this process shows no turret ranks can hit the target.

Re: [2.0.72] Turrets firing at targets they cannot hit [mods]

Posted: Sat Nov 08, 2025 4:50 am
by wtgibson
Turning off K2SO's "Realistic weapons" setting ensures that all shots fired can hit their targets, fixing this issue.

I still think this outcome shouldn't be possible, but maybe it's not an engine 'issue' then?
Unfortunately for me, the settings in these two mods are Startup settings, so I guess my game is kind of stuck with this issue?

Re: [2.0.72] Turrets firing at targets they cannot hit [mods]

Posted: Sat Nov 08, 2025 11:03 am
by jodokus31
wtgibson wrote: Sat Nov 08, 2025 4:50 am Turning off K2SO's "Realistic weapons" setting ensures that all shots fired can hit their targets, fixing this issue.

I still think this outcome shouldn't be possible, but maybe it's not an engine 'issue' then?
Unfortunately for me, the settings in these two mods are Startup settings, so I guess my game is kind of stuck with this issue?
If you mean Mod settings -> Startup, you just have to restart the game to take effect.
What do mean with stuck? You shouldn't need to restart the playthrough.

Re: [2.0.72] Turrets firing at targets they cannot hit [mods]

Posted: Sun Nov 09, 2025 2:59 am
by wtgibson
Derp I misunderstood those settings, I thought they affected only new games. Thanks jodokus31.
Practically, I can't disable Realistic Weapons because it deletes all the ammunition without replacement.
However I can workaround by decreasing turret range bonus.