Weapon accuracy, tracking, wobble, etc

Weapon accuracy, tracking, wobble, etc

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Posts: 251
Joined: 27 Jun 2007, 17:05

Weapon accuracy, tracking, wobble, etc

Post by ivand »


I'm writting a gadget, crucial helper function of which should return a probability if particular weapon (of particular unit) can hit a target.

Up to the certain point I have progressed ok and took into account, besides the obvious things like target's speed, projectile speed and distance, weapon's accuracy, sprayAngle, and radar wobble (allyteamErrorSize). For the sake of future reuse I'm putting code snippet that covers those variables:

Code: Select all

--unitWD -weapondef
--factors that affect accuracy in negative way	
local scatter = unitWD.accuracy or 0 + unitWD.sprayAngle or 0

local allyteamErrorSize = 0
if not (targetInLoS or targetIdentifiedStatic) then 
	allyteamErrorSize = Spring.GetRadarErrorParams(allyTeam) --apply radar wobble

distance3D -- is 3D distance between unit and target, may well be distance in 2D
local scatterRadius = scatter * distance3D + allyteamErrorSize
-- targetRadius is target's XZ hit volume
local hitScatterProbability = 1 - math.max( (scatterRadius-targetRadius)/scatterRadius , 0 ) --prevent values < 0
However, the point I'm kind of stuck with missile projectiles. Specifically w.r.t. properties such as wobble, dance and turnRate. The meaning of each parameter is known as well as what changes it does to the projectile in flight, however I found it diffucult to find some kind of algorithm or formula to estimate the shape and size of possible area of damage (if wobble overpowers tracking) or if a target given it's speed can dodge the missile (if tracking dominates).

Can someone help?
Posts: 169
Joined: 08 Jul 2015, 20:20

Re: Weapon accuracy, tracking, wobble, etc

Post by 8611z »

No real solution, more random ideas. This widget does something similiar:
https://github.com/ZeroK-RTS/Zero-K/blo ... ck_aoe.lua

To calculate the possible spread of a ballastic projectile the widget loops through different sprayAngles and then calculates the path of all those 'virtual projectiles' until they hit the ground.
The percentage of those 'virtual impacts' that get near the target could tell how likely it is to hit.

Similiar could work with missile projectile too, the formulas can be found in engine. Maybe with different paths of target too. (continue current direction, turn left/right)
Limited by how much cpu time the calculations are allowed to take.

Other idea might be to start with various simple cases.
Is missile is slower than the target and behind the target, then the missile will never catch up.
If the missile is faster than target, then it must cover the distance before its fuel runs out.
That allows to throw out some cases where one quickly sees that hitting target will be impossible, and then can skip finer calculation.
Then add in more factors, like different directions of missile and target, accelerating missile, minimum turning radius of the tracking missile,
if wobble overpowers tracking
maybe https://github.com/ZeroK-RTS/Zero-K/blo ... e.lua#L200
Not sure how the author found the 1.4 factor, whether that was calcultated or found through experimenting.
User avatar
Posts: 251
Joined: 27 Jun 2007, 17:05

Re: Weapon accuracy, tracking, wobble, etc

Post by ivand »

Hi and thanks for replying @8611z!

The widget you've mentioned was my source of inspiration until I found out it actually gives wrong results if you change missile parameters here and there. Although, yeah It actually gives sane results for range of values ZK uses.

Next comes semi-structured talk with regards to what I've thought about so far.

Firstly tracking:
Hypotenuse of each triangle represent where projectile might end if maximum per-frame tracking is applied. Each triangle then represents frame. Drawing is slightly incorrect but general idea should be clear. Next the maximum angle missile could turn to from starting location is represented by formula:

Code: Select all

(n+1)Alpha/2, where n is number of frames and alpha is maximum tracking angle (per frame)
for n = 1 (one triangle) we get alpha
for n = 2 (two triangles) we get 3/2 * alpha,
Not sure how above information is useful, but I decided to leave it here as I go.

Next I'm a little bit in doubts, how pure tracking information should be used against target speed.
Consider picture: Image
Let's ignore for a moment unit has turn radius or inertia. Assume it can gain certain speed in certain direction and moved to where arrow points before frame started. It seems to me that ability to hit the target in this case depends greatly whether target is "closer" to end of frame. Anyway so far straight comparison of target per-frame speed and missile possible tracking deviation got me wrong results, so I'm likely stuck here.

Now wobble. Wobble applies certain vector every frame, very similar to what tracking does, except that every 16 frames missile gets new random vector. As random variables are independently set each 16 frames we come to what's called Irwin–Hall distribution (https://en.wikipedia.org/wiki/Irwin%E2% ... stribution) (sum of uniform random variables). Which is basically resemble bell curve very closely after n>3 random samples. Knowing it's a bell curve and also knowing mean and variation of that curve, it's easy to estimate the area where projectiles would hit with like 99% probability (take infamous 3 sigma or less), However in this case speed of projectiles play a vital role. See fast vs relatively slow missile hit area:
Also slower projectiles fly longer, so they get more of wobble vector randomizations than faster ones. Anyway despite above findings I still have very little idea how to make estimation of what area missiles will likely to hit, given their speed and wobble factor.

Obviously since both questions are still open, I can't say a thing how would wobble + tracking works.

I feel like I'm over-engineering things here, maybe something simpler should be used, thus the reason why I created the topic.
Post Reply

Return to “Lua Scripts”