After all this work I think I've developed something that works decently:
I still have some testing to do but calculating a velocity vector based on the change in position in 1 frame seems to be giving decent results. The only real issue at this point is that the trap is an arcing projectile. I could probably find some gravitational equation to roughly guess the time of travel based on an arc.
Code:
function PredictTrapPosition2(unit)
unit = unit or 'target'
local framerate = GetFramerate();
local x1, y1, _,_,_ = GetUnitPosition(unit)
local startTime = GetTime()
C_Timer.After(.1, function()
if UnitExists(unit) then
local x2, y2,z,_,_ = GetUnitPosition(unit)
local px, py,_,_,_ = GetUnitPosition('player')
local endTime = GetTime()
local dx,dy,dz
dx = (x2-x1) / (endTime - startTime)
dy = (y2-y1) / (endTime - startTime)
dz = 0
local distance = math.sqrt((x2 - px)^2 + (y2 - py)^2)
local flightTime = distance / 25 * cos((30 * 3.1459) /180) --Works nicely decreases as target gets closer.
local x = x2 + dx * flightTime
local y = y2 + dy * flightTime
local newz = z;
while InLineOfSight(x,y,z,x,y,newz,4) == 0 do
newz = newz - 5;
end
AceRunMacroText("/script ClickPosition("..x..","..y..","..newz..")")
end
end)
end