Projectile Collision - Best Way To Detect When A Missile Hits A Unit?

El-Sevio

New Member
Reaction score
0
Hellooo thar!

In order to programme my own knockback system for missiles, I was wondering what the most effective way of detecting when a unit is hit with a missile?

For the missile I create it as a unit, and manually trigger its movement, using Jass.







Things that come to mind atm are either checking every x seconds if any missile unit is in range of an enemy, then creating the collision then.

Or having the collision actions in a trigger with no events, then a seperate trigger that takes every new unit added to the game (event - Unit enters playable map area), and then adds the event to the collision trigger "(A unit enters 50 range of (trig unit).

The first one seems inefficient and the second one doesnt work for different missile shapes and sizes without making a new trigger with 100 odd events for each missile.






This is the missile create code :)
First Function is for moving the missile, and uses katana's handle system to use locals from another function (the bottom one)

Second fuction is triggered when a unit casts the missile of course =)

Code:
function Missile takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit missile = GetHandleUnit(t, "missile")
local real direction = GetHandleReal(t, "angle")
call SetUnitPositionLoc(missile, PolarProjectionBJ(GetUnitLoc(missile), 100.00, direction))
set t = null
set missile = null
endfunction

function ExecuteMissile takes nothing returns nothing
local unit c = GetTriggerUnit()
local real direction = AngleBetweenPoints(GetUnitLoc(c),  GetSpellTargetLoc())
local timer t = CreateTimer()
local integer p = GetConvertedPlayerId(GetOwningPlayer(c))
local unit u
call TriggerSleepAction(0.25)
set u = CreateUnitAtLoc(GetOwningPlayer(c), 'h01L', GetUnitLoc(c), direction) 
call SetHandleHandle(t, "missile", u)
call SetHandleReal(t, "angle", direction)
call TimerStart(t, 0.035, true, function Missile)
call TriggerSleepAction(0.5)
call FlushHandleLocals(t)
call DestroyTimer(t)
call RemoveUnit(u)
set c = null
set t = null
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top