2018-08-27, 12:55 AM

i was trying to write a code to get missiles to cruise at 400m until within 100m horizontally from the target, then cut engines and glide down to impact (using APN), but i can't seem to get it to work. any help would be greatly appreciated, i'm still fairly new to LUA. i'm also not sure if "missileData.throttle" is a real thing or not, if not could you please let me know what i actually need to do to change thrust in a variable missile?

function Speed(vel)

return math.sqrt(vel.x^2 + vel.y^2 + vel.z^2)

end

function Distance(a,b)

return math.sqrt((a.x - b.x)^2 + (a.y - b.y)^2 + (a.z - b.z)^2)

end

function Update(I)

for t=0,I:GetLuaTransceiverCount() do

for m=0,I:GetLuaControlledMissileCount(t) do

missileInfo = I:GetLuaControlledMissileInfo(t, m)

targetInfo = I:GetTargetInfo(0, 0)

if(targetInfo.Valid == false or targetInfo.Protected == false) then

break

end

Pos = missileInfo.Position

TSpeed = Speed(targetInfo.Velocity)

TPos = targetInfo.AimPointPosition

V = targetInfo.Velocity

D = Distance(Pos, TPos)

S = Speed(TSpeed-missileInfo.Velocity)

PDis = math.sqrt((Pos.x-TPos.x)^2 + (Pos.y-TPos.y)^2)

Time = D/S

if (PDis >100)

I:SetLuaControlledMissileAimPoint(t,m,TPos.x,400,TPos.z)

end

else

missileData.throttle = 0

I:SetLuaControlledMissileAimPoint(t,m,TPos.x,TPos.y,TPos.z)

end

end

function Speed(vel)

return math.sqrt(vel.x^2 + vel.y^2 + vel.z^2)

end

function Distance(a,b)

return math.sqrt((a.x - b.x)^2 + (a.y - b.y)^2 + (a.z - b.z)^2)

end

function Update(I)

for t=0,I:GetLuaTransceiverCount() do

for m=0,I:GetLuaControlledMissileCount(t) do

missileInfo = I:GetLuaControlledMissileInfo(t, m)

targetInfo = I:GetTargetInfo(0, 0)

if(targetInfo.Valid == false or targetInfo.Protected == false) then

break

end

Pos = missileInfo.Position

TSpeed = Speed(targetInfo.Velocity)

TPos = targetInfo.AimPointPosition

V = targetInfo.Velocity

D = Distance(Pos, TPos)

S = Speed(TSpeed-missileInfo.Velocity)

PDis = math.sqrt((Pos.x-TPos.x)^2 + (Pos.y-TPos.y)^2)

Time = D/S

if (PDis >100)

I:SetLuaControlledMissileAimPoint(t,m,TPos.x,400,TPos.z)

end

else

missileData.throttle = 0

I:SetLuaControlledMissileAimPoint(t,m,TPos.x,TPos.y,TPos.z)

end

end