I've looked around and almost all examples is see have a velocity vector which I do not have, or at this point am unable to figure out. Im trying to find the 3D position where i can launch a trap in game to land in the targets path of movement assuming constant speed.
What I do Have
Two Coords: Initial and a second set of X,Y,Z after 1 frame. Unit speed as a number from the game, hoping i can calculate a better number based on the one frame difference above. The speed of the trap - 25yards/s The time between frames 1/ Games current FrameRate
This works on still targets but I cannot find out how to get the units speed into the calculation:
function PredictTrapPosition(unit) unit = unit or 'target' local x1, y1, _ = UnitPosition(unit) --forget z assume they are running on flat ground. C_Timer.After(1/GetFrameRate(), function() -- after one frame local x2, y2, z = UnitPosition(unit) local px, py, _ = UnitPosition('player') --My position local distance = math.sqrt((x2 - px)^2 + (y2 - py)^2) local trapSpeed = distance / 25 -- trap travel time. local angle = atan2(x2-x1, y2-y1) local x = x2 + cos(angle) * trapSpeed local y = y2 + sin(angle) * trapSpeed WorldClick(x, y, z) end)
Hopefully a math guru can chime in and help me fix this probably simple formula.