beyond-all-reason / spring

A powerful free cross-platform RTS game engine
https://beyond-all-reason.github.io/spring/
Other
210 stars 100 forks source link

Fix units switching between two targets rapidly #1453

Closed marcushutchings closed 4 months ago

marcushutchings commented 5 months ago

Addresses the issue where units can sometimes find themselves switching back and forth between two targets that are similar distance and angle. For slower rotating turrets, this can prevent them opening fire. Units without a specific attack target check for targets on slow update, the random element can cause two similarly viable targets to cause units to switch between the targets each time.

https://cdn.discordapp.com/attachments/724924957074915358/1230113372322795540/golswing.mp4?ex=6632235a&is=661fae5a&hm=ede9cabe20e2cf7894ef3f279dacf9721199d8e574a382af3863848d8cc9f193&

marcushutchings commented 5 months ago

Note, games using their own targetting priorities are not impacted by this change. This change only affects games using the engine's internal targeting priority calculations.

badosu commented 5 months ago

Is there a rationale for previous behavior? I'd like to understand (if any) what was the idea.

sprunk commented 5 months ago

It comes from a time before Lua had control (so was implementing game design) and I believe it was meant to partially avoid all units picking the same target when there are multiple similar choices available and partially reduce rigidness. Regardless, Lua can add the component back if desired (while currently you can't do the opposite and cancel the random component out, other than reimplementing the whole calculation from scratch).

lhog commented 5 months ago

What is the rationale to scan targets every two seconds or so, if the current target is valid?

marcushutchings commented 5 months ago

Probably to make sure the unit is targetting the best unit - with units moving about during combat, it likely helps break up any excessive over targetting of one unit.

marcushutchings commented 5 months ago

It is only done during auto target.

marcushutchings commented 5 months ago

If you give the unit a specific target, then it will stay on that target.

sprunk commented 5 months ago

What is the rationale to scan targets every two seconds or so, if the current target is valid?

Otherwise everything would get stuck on the first thing that enters range.