I am trying to write a movement prediction code. I have found the quadratic method with these topics:
- [1]: How to calculate shot angle and velocity to hit a moving target?
- [2]: http://howlingmoonsoftware.com/wordpress/leading-a-target/
I have implemented this without problems. The problem is how can I add enemy hitbox calculation (I want to fire at edge of enemy for precision)
local cos = targetDirection:dot(toTargetDirection)
local absCos = math.abs(cos)
local sin = math.sqrt(1 - (cos * cos))
local absSin = math.abs(sin)
local cot = cos / sin
local absCot = math.abs(cot)
local delta = 1 - ((cos * cos) + (sin * sin))
local position = targetPosition + targetVelocity * delay
position = position + targetVelocity * network.latency
position = position - toTargetDirection * (target.boundingRadius + width)
position = position - targetDirection * (target.boundingRadius + width)
position = position - toTargetDirection * (absSin * (target.boundingRadius +
width))
position = position - targetDirection * (absCos * (target.boundingRadius +
width))
local toPosition = position - sourcePosition
local toPositionDirection = toPosition:norm()
local spellVelocity = toPositionDirection * speed
local a = targetVelocity:dot(targetVelocity) -
spellVelocity:dot(spellVelocity)
local b = targetVelocity:dot(toPosition) * 2
local c = toTarget:dot(toPosition)
local discriminant = b * b - 4 * a * c
if (discriminant < 0) then
return
end
local time = 2 * c / (math.sqrt(discriminant) - b)
So far tried this but it's still not casting edge with precision.