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
 

cleeezzz

The Undead Ranger.
Reaction score
268
everytime you move the missile, group units in range matching unit is an enemy and damage them.
 
Reaction score
341
Register the missle event , UnitComesWithinRange( range, unit) , thats not the exact event. I dont have world editor open.
 

El-Sevio

New Member
Reaction score
0
i can check if it is in range each time i move it.



I think the event one wont work too well because if I use more then 1 missile with different radius's, the range will be different. One trigger per missile with 100 odd events in each ( one per unit in the game) wouldn't be too desirable.

I'll just check if enemy unit is in range of missile each time i move it, then cause damage and remove missile, like cleeez mentioned

But thanks v much both of u
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
Why can't you use just check the distance between them and execute your actions?

JASS:
function Slide_Effect takes nothing returns nothing
    local timer Loop = GetExpiredTimer()
    local unit Caster = H2U(GetHandleHandle(Loop, "Caster"))
    local real Angle = GetHandleReal(Loop, "Angle")
    local real Distance = GetHandleReal(Loop, "Distance")
    local real N = GetHandleReal(Loop, "N")
    local location CasterPosition = GetUnitLoc(Caster)
    local location MoveToPoint
    local effect Effect

    if ((N <= Distance) then
        set N = N + 20
        call SetHandleReal (Loop, "N", N)
        set MoveToPoint = PolarProjectionBJ(CasterPosition, 20.0, Angle)
        call SetUnitPositionLoc(Caster, MoveToPoint)
        set Effect = AddSpecialEffectTarget("Abilities\\Weapons\\AncientProtectorMissile\\AncientProtectorMissile.mdl",Caster,"origin")

        call DestroyEffect(Effect)
        call RemoveLocation(MoveToPoint)
        call RemoveLocation(CasterPosition)
        set Caster = null       
    else                        
        call PauseTimer(Loop)        
        call PauseUnit( Caster, false )
        call ResetUnitAnimation( Caster )                
        call SetUnitPathing( Caster, true )

        call RemoveLocation(MoveToPoint)
        call RemoveLocation(CasterPosition)
        set Caster = null        
        call FlushHandleLocals(Loop)
        call DestroyTimer(Loop) 
    endif
   
endfunction

function Slide_Actions takes nothing returns nothing
    local timer Loop = CreateTimer()
    local unit Caster = GetSpellAbilityUnit()
    local location CasterPosition = GetUnitLoc(Caster)
    local location TargetPosition = GetSpellTargetLoc()
    local real Angle = AngleBetweenPoints(CasterPosition, TargetPosition)
    local real Distance = DistanceBetweenPoints(CasterPosition, TargetPosition)


    call TriggerSleepAction( 0.20 )
    call PauseUnit( Caster, true )
    call SetUnitAnimation( Caster, "spell channel" )
    call SetUnitPathing( Caster, false )
    
    call SetHandleHandle(Loop, "Caster", Caster)
    call SetHandleReal(Loop, "Angle", Angle)
    call SetHandleReal(Loop, "Distance", Distance)

    call TimerStart(Loop, 0.03, true, function Slide_Effect)

endfunction


FYI Handle Vars are outdated.
 

Charapanga

New Member
Reaction score
46
Distance between points / Missle speed would be the most accurate...
Or the Unit in range thing ^^ whatever you'd like...
 

El-Sevio

New Member
Reaction score
0
You can do a GroupEnumUnitsInRange (which would be safest, since the UnitEntersRange event would require dynamic triggers which apparently can caused bugs with the handle stack of something), then if CountUnitsInUnitGroup > 1, pick a random unit from the group (assuming you only want single target to be hit), and do your actions

awesome, yep thats what I've done now I used the GroupEnumUnitsInRange.

But i wanted aoe effect for one of them so I removed allied units from the group and damaged each one within a different explosion radius to the collision radius.
 

El-Sevio

New Member
Reaction score
0
"Why can't you use just check the distance between them and execute your actions?"


Thanks for teh helps!

I read ur code but Im not quite sure what it does =) what does it dooo?

is it a knockback? Cuz I just use silvenon's function heheee. Or is it moving the missile + detecting collision??

And what replaces handles now, hahah?
 

El-Sevio

New Member
Reaction score
0
everytime you move the missile, group units in range matching unit is an enemy and damage them.


Hey cleeezzz, btw I knew there was a map that I'd played before that had exactly what I wanted, I searched for it, found out it was Archer Wars, then I realised that it was u who made it!! (Based on the minimap prev. obviously)

Small worllld!!
 

El-Sevio

New Member
Reaction score
0
Hey and Cleeze, one of my units is an archer =). My arrow fires fine and what not, but I cant master the positioning and it seems to miss even if it hits and its sort of slightly off-target and just doesnt feel right. As opposed to Archer Wars firing. Can you answer these questions? Dont worry my map is v. different from Archy Wars :)

What is the flying height of your arrow?

Do you search for units in range each time you move the arrow, in order to find your collision?


What is the reset duration on the timer of moving the arrow? (e.g. 0.035)

How many units do you move the arrow towards the direction every time the timer executes?

e.g.(call SetUnitPositionLoc(arrow, PolarProjectionBJ(GetUnitLoc(arrow), 60.00, direction))
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage

      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