# Leading a target with edge casting

I am trying to write a movement prediction code. I have found the quadratic method with these topics:

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.

• Looks like nobody is know the solution :( Jan 24, 2019 at 19:56
• Two possibilities: 1) Nobody knows how to do hitbox calculation (unlikely) 2) Nobody has a clear idea what kind of help you need with hitbox calculation. So, try editing your question to explain in detail what you've tried so far and where you're stuck, or how the results you're getting differ from what you want. Editing to add detail attracts more attention to questions, and makes it easier to write high-quality answers. Jan 24, 2019 at 20:09
• Updated. I want to cast edge because i want to increase hitchance in low range. Jan 25, 2019 at 15:50
• Can you walk us through (or even diagram) an example of how casting an edge gives better hit chance than the alternative you have in mind? Jan 25, 2019 at 16:24
• In mid-short range target can't dodge with backward/inverse movement. It depends on speed. Jan 25, 2019 at 18:05