• 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] Unit in range using collision

Status
Not open for further replies.
Level 12
Joined
Feb 23, 2007
Messages
1,030
Assuming the units Point Value = Collision size, would this be a good check to see if they are within a certain range?

JASS:
function UnitInRange takes real r, unit u, real x, real y returns boolean
local integer p = GetUnitPointValue(u)
local real x2 = GetUnitX(u)
local real y2 = GetUnitY(u)

return SquareRoot((x2-x)*(x2-x)+(y2-y)*(y2-y)) < r+p
endfunction
 
Last edited:
Level 12
Joined
Feb 23, 2007
Messages
1,030
But does it take into account their collision size? I want it to where if there fattyness is within range than it selects them. Say I code a grenades damage and have it damage units in 100 AoE. It could land right next to a town hall and not damage it at all even though the town halls fat is in range.

See what I'm trying to do?
 
Level 12
Joined
Feb 23, 2007
Messages
1,030
So i'm trying to pick units in range using this and then damage them.
Should I select all units on the map and then use that function you posted?

JASS:
call GroupEnumUnitsInRange(g,x2,y2,100+MC(),Condition(function RipperFilter))
(MC() is the largest collision size of any unit in the game)

Also is it bad to mimic natives with your own code? Are natives always faster?
JASS:
private function RipperFilter takes nothing returns boolean
local integer p = GetUnitPointValue(GetFilterUnit())
local real x2 = GetUnitX(GetFilterUnit())
local real y2 = GetUnitY(GetFilterUnit())

return SquareRoot((x2-TempReal1)*(x2-TempReal1)+(y2-TempReal2)*(y2-TempReal2)) <= TempReal3+p
endfunction

I just tested your function and it didn't work. I set the dudes collision size to 300 and threw the grenade a short distance away. Didn't hurt him.
 
Status
Not open for further replies.
Top