T
the.Seeker
Guest
Hello
Say that i have an artillery unit and a target unit. The target unit is moving in a straight line, and is a few screens away from the artillery.
The artillery is supposed to predict the target unit's movement and shoot accordingly. The projectile speed of the artillery is 2000/second. The projectile arc is 15°.
I have come up with a fairly complex formula which does sort of work, but what happens that the artillery shoots in front of the target. At distances like 2000-3000 this is not a problem, but at distances of 5000 or so it starts to get inaccurate.
So take a look and see if you can help me improve this formula, or the system:
The whole thing calculates the location that the artillery is supposed to shoot at to hit the target.
The location that it returns though is always a bit in front of the target because i don't know any way to calculate the exact location. Maybe you can help?
Also, i think the GetProjectileArcLength is not completly working as intendend, as the ArcLength that it calculates it barely bigger than the straight distance between the artillery and the target.
Say that i have an artillery unit and a target unit. The target unit is moving in a straight line, and is a few screens away from the artillery.
The artillery is supposed to predict the target unit's movement and shoot accordingly. The projectile speed of the artillery is 2000/second. The projectile arc is 15°.
I have come up with a fairly complex formula which does sort of work, but what happens that the artillery shoots in front of the target. At distances like 2000-3000 this is not a problem, but at distances of 5000 or so it starts to get inaccurate.
So take a look and see if you can help me improve this formula, or the system:
Code:
function GetProjectileArcLength takes location artilleryLoc, location x, real firingAngle returns real
local real radius = (DistanceBetweenPoints(artilleryLoc, x)/2)/(CosBJ(90-firingAngle))
local real projectileArcLength = (radius * Deg2Rad(firingAngle*2))
return projectileArcLength
endfunction
function TrackTarget takes location artilleryLoc, location targetInitialLoc, location targetCurrentLoc, real timePassed returns location
local real projectileSpeed = 2000.00
local real projectileFiringAngle = 15.00
local real targetSpeedPerSecond = (DistanceBetweenPoints(targetInitialLoc, targetCurrentLoc) * (1/timePassed))
local location x = targetCurrentLoc
local real projectileTravelDist
local real projectileTravelTime
set projectileTravelDist = GetProjectileArcLength(artilleryLoc, x, projectileFiringAngle)
set projectileTravelTime = projectileTravelDist/projectileSpeed
set x = PolarProjectionBJ(targetCurrentLoc, projectileTravelTime*targetSpeedPerSecond, AngleBetweenPoints(targetInitialLoc, targetCurrentLoc))
set projectileTravelDist = GetProjectileArcLength(artilleryLoc, x, projectileFiringAngle)
set projectileTravelTime = projectileTravelDist/projectileSpeed
set x = PolarProjectionBJ(targetCurrentLoc, projectileTravelTime*targetSpeedPerSecond, AngleBetweenPoints(targetInitialLoc, targetCurrentLoc))
return x
endfunction
The whole thing calculates the location that the artillery is supposed to shoot at to hit the target.
The location that it returns though is always a bit in front of the target because i don't know any way to calculate the exact location. Maybe you can help?
Also, i think the GetProjectileArcLength is not completly working as intendend, as the ArcLength that it calculates it barely bigger than the straight distance between the artillery and the target.