Guys help me! I suck at math!
So, what I'm trying to do is cast a spell to a target unit. That spell fires a missile, predicting where this target is currently moving. It's like the default missile attack with Homing set to false.
I already searched a bunch examples and references at gamedev and other sites but I can't just make it work!
This is my function, which I salvaged from gamedev and converted it to vjass.
I'm sorry if I'm being picky, but if you can, please spare me with complex math lectures or attach link of math equation stuffs. I can't understand it anyway nor interested in it!
If you would be so kind, just give me a function that works T-T
So, what I'm trying to do is cast a spell to a target unit. That spell fires a missile, predicting where this target is currently moving. It's like the default missile attack with Homing set to false.
I already searched a bunch examples and references at gamedev and other sites but I can't just make it work!
This is my function, which I salvaged from gamedev and converted it to vjass.
JASS:
function intercept takes UNIT src, UNIT trg, real bulletSpeed returns nothing
// position
local real dx = src.x - trg.x
local real dy = src.y - trg.y
// velocity
local real vx = src.vx - trg.vx
local real vy = src.vy - trg.vy
local real a = vx * vx + vy * vy - bulletSpeed * bulletSpeed
local real b = 2. * (vx * dx + vy * dy)
local real c = dx * dx + dy * dy
local real disc = b * b - 4. * a * c
local real t0
local real t1
if (disc >= 0) then
set t0 = (-b - SquareRoot(disc)) / (2. * a)
set t1 = (-b + SquareRoot(disc)) / (2. * a)
if (t0 < 0. or (t1 < t0 and t1 >= 0.)) then
set t0 = t1
endif
if (t0 >= 0.) then
set TARGET_X = vx + dx / t0
set TARGET_Y = vy + dy / t0
endif
endif
endfunction
I'm sorry if I'm being picky, but if you can, please spare me with complex math lectures or attach link of math equation stuffs. I can't understand it anyway nor interested in it!
If you would be so kind, just give me a function that works T-T