• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

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

Status
Not open for further replies.
Level 3
Joined
Jun 14, 2007
Messages
56
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 :)
JASS:
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
 
Last edited by a moderator:
Explain counting the unit's touching it... Would that be using a "Get all units in radius" kind of approach? If not, then how? :confused:

as ghost wolf said, yes.

You'd do something like this

JASS:
globals
     integer tempTouchingCount
endglobals

function damage takes nothing returns nothing
     call damageUnit(GetEnumUnit(),integer)
endfunction

function add1 takes nothing returns nothing
     set tempTouchingCount = tempTouchingCount+1
endfunction

function countUnits takes nothing returns nothing
     set tempTouchingCount = 0
     call ForGroup(Units within 70,function add1)
     if tempTouchingCount>0 then
          call ForGroup(units within 70,function damage)
          call RemoveUnit(missile)
     endif
endfunction

Not real jass of course but this should convey my point.

in the add1 and damage functions you could check unit type and player alliance, or anything else really.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Use CreateCorpse() then set life to more than 0 to create an "alive" unit (flagged dead, but appears alive to GetWidgetLife() > 0) which is unselectable but able to be found by groupenums.

Neat.

Bla bla bla

That approach is kind of ugly.

JASS:
function meh takes something returns something
    local unit u = <some unit>  
    local unit temp 
    local group g = CreateGroup()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    set g = GroupEnumUnitsInRange(g,x,y,<some radius>,null)

    loop
        set temp = FirstOfGroup(g)
        exitwhen temp == null
        call GroupRemoveUnit(g,temp)
        if <some conditions with temp> then
            <actions>
        endif
    endloop
    
    set u = null
    call DestroyGroup(g)
    set g = null
endfunction
 
Level 3
Joined
Jun 14, 2007
Messages
56
"You might want to stop using all those BJs and Handlevars, and you also leak a few locations."

whats wrong with Handlevars? Is that the "GetHandleUnit" functions etc? Or am i doing something wrong with unit locals and other handle locals?

Oh and what do i replace BJs with?

EDIT1:
"Use CreateCorpse() then set life to more than 0 to create an "alive" unit (flagged dead, but appears alive to GetWidgetLife() > 0) which is unselectable but able to be found by groupenums."


What does above do? Is it just a good thing to do for missile units?

EDIT2:
thanks for the help Ghostwolf, yeah thats what i ended up doing almost exactly.

Dont u have to re set temp to FirstOfGroup(g) again before the endloop (once you've removed temp from the group)? Or else it doesnt check any other units?

EDIT3:
And on another note thanks very much for all help, much appreciated~!
 
Last edited by a moderator:
  • Angry
Reactions: Rui
Level 29
Joined
Jul 29, 2007
Messages
5,174
whats wrong with Handlevars?

It's old. It was never really stable and not buggy, after all it mainly relays on a bug (H2I), but there wasn't any other solutions to move locals between functions (beside Vexorian's system which I think did the same thing).

Now there are better solutions using vJass. I never really tried any of them because I don't code for warcraft but you can find any info you want in the vJass manual.

Oh and what do i replace BJs with?

With non BJ functions?

Almost all of the BJ functions (located in Blizzard.j) are useless and just call native functions. Why did Blizzard make them? They are retards.

Anyhow, beside PolarProjectionBJ, DistanceBetweenPoints, and AngleBetweenPoints there are natives for almost every BJ function.

Those three functions are actually just fine, but usually people prefer to use coordinates over locations (which mean you would need to implement this three functions with coordinates, which is pretty darn easy) since there is no need to clean them.

Just as an example of a useless chain of BJs, I introduce you to the IsUnitAliveBJ function:

JASS:
function IsUnitAliveBJ takes unit whichUnit returns boolean
    return not IsUnitDeadBJ(whichUnit)
endfunction

Which as you can see calls IsUnitDeadBJ

JASS:
function IsUnitDeadBJ takes unit whichUnit returns boolean
    return GetUnitState(whichUnit, UNIT_STATE_LIFE) <= 0
endfunction

Which calls GetUnitState which is a native.
That's what can be called, useless BJ :p

"Use CreateCorpse() then set life to more than 0 to create an "alive" unit (flagged dead, but appears alive to GetWidgetLife() > 0) which is unselectable but able to be found by groupenums."


What does above do? Is it just a good thing to do for missile units?

Apparently it's another way to make un-selectable units.

Dont u have to re set temp to FirstOfGroup(g) again before the endloop (once you've removed temp from the group)? Or else it doesnt check any other units?

It sets temp to the first unit of g with each iteration BEFORE it can exit the loop and therefore it will only exit when temp is null which means g is empty.
 
Level 3
Joined
Jun 14, 2007
Messages
56
Oh okie, I guess i'd better start learning structs theeen.



Whats the best way to find all these natives that correspond with the BJ functions???





Yeah true I'll get round to changing to co ordinates i think ur right






"It sets temp to the first unit of g with each iteration BEFORE it can exit the loop and therefore it will only exit when temp is null which means g is empty."



And I understand about the loop thing now, thnx







Hey man, thanks for all this help, you'sa legenddd:D:D
 
Level 3
Joined
Jun 14, 2007
Messages
56
The reason I suggest CreateCorpse is because it's a way to handle unselectable units that means they are much easier to work with in terms of detection. Depending on what you're doing, this can be a really good thing, or perhaps a bad thing.

As for the main detection, enums are fine.


ohhh ok i see, thanks for the tip i'll give it a try instead of locust although tbh i cant think of any reasons why it would be easier to detect them off the top of my head but thanks =)
 
Level 3
Joined
Jun 14, 2007
Messages
56
ohh okay i didn't quite get the fact that JNGP was jass newgen (plugin?) wasnt sure what it was i thought we were talking about jasscraft

lol double posting
 
Level 3
Joined
Jun 14, 2007
Messages
56
..... i didnt think double posting itself is funny....

i was laughing at myself after being told not to i accidentally did it again.

its kinda of a habbit.

why is double posting a problem? i had no idea about this rule. and yes i should have searched for rules before posting and i'm sure you're jumping to say this to me so well done buddy
 
Level 3
Joined
Jun 14, 2007
Messages
56
wow what an anal-retentive scheme. negative repping someone for making his posts hard to read by double posting. in my opinion it reads easier - adds some structure. the way i post it is the way i would have said it - the post difference highlights the time difference and reads the way i want it to, not because i want to get a high post count.

and im not very worried if i have negative rep not if you're given this for something as trivial as double posting. how uptight is that
 
Level 6
Joined
Sep 5, 2007
Messages
264
Arguing and trash talking the forum rules an even better way of getting negative rep.

Just say OK and do it.
Well said.

wow what an anal-retentive scheme. negative repping someone for making his posts hard to read by double posting. in my opinion it reads easier - adds some structure. the way i post it is the way i would have said it - the post difference highlights the time difference and reads the way i want it to, not because i want to get a high post count.

and im not very worried if i have negative rep not if you're given this for something as trivial as double posting. how uptight is that
You may not be "afraid"... But, repeat offences will get you banned. The admins here have these rules for a reason. A very vast majority of people like the rules, and stick to them. The rules say that double-posting is not allowed. If you feel the urge to double-post, then edit the previous post.
It's not a hard rule to follow.

EDIT: As for reading "easier"... This topic is now on its 3rd page, when it'd barely be on its 2nd, without all the double-posts.
 
Level 3
Joined
Jun 14, 2007
Messages
56
Arguing and trash talking the forum rules an even better way of getting negative rep.

Just say OK and do it.

the moral of a sheep..

EDIT: As for reading "easier"... This topic is now on its 3rd page, when it'd barely be on its 2nd, without all the double-posts.

Your post would be on the SECOND PAGE! All thanks to evil double posting??? I feel so guilty! Not too hard to read if the thread is spaced out over more than one page. The fact that we are arguing about this points out how trivial this whole discussion is..


It's not a hard rule to follow.
I know its not...i'm following it from now.... i'm not continuing to break the rules i'm just arguing against them. Cokemonkey was the one who started being hostile i just said "lol double posting" to refer to my mistake. i havent done it again since then. he comes and shuts me down with ""lol" doesnt make it funny. It's against the rules; don't do it.'... thanks mate
 
Status
Not open for further replies.
Top