Loc/Angle Jass question

AKDevil

New Member
Reaction score
1
im currently making an ability (cleave) where i want it to target one unit, and also damage up to 2 additional units (if there), which have to be within melee range of the caster, and within 60* of the target, relative to the angle of the line between the caster and target. could someone make me an example? mostly just need the angles and math, but the rest of the spell would be great to have for a reference.

BTW, heres the spell
cleave : strikes one target for X damage, and u to 2 nearby enemies in front and in melee range of the caster for 1/2 of the damage to the main target, if they are there. if one or both the additional targets are not there, the remaining target(s) take 1/2 of the missing targets damage distributed between them.
 

NotInTheFace

Member
Reaction score
17
mostly just need the angles and math,

Here's the math:

To get the angle between 2 points, it's Atan2(toY-fromY, toX-fromX)

To get the distance between 2 points, it's SquareRoot(dx*dx + dy*dy) where dx = toX-fromX and dy = toY - fromY
 

AKDevil

New Member
Reaction score
1
thanks NotInTheFace, i think that is what i have, but could i get an example for all of the angle and location stuff, like in jass tags?
 

NotInTheFace

Member
Reaction score
17
thanks NotInTheFace, i think that is what i have, but could i get an example for all of the angle and location stuff, like in jass tags?

Hmm, let's see if I can do this off the top of my head.

JASS:

function checkRangeAndAngle takes unit unit1, unit unit2, real maxAngle, real maxDistance returns boolean
local real xFrom = GetUnitX(unit1) //this will be the unit doing the cleave
local real yFrom = GetUnitY(unit1)
local real xTo = GetUnitX(unit2) //this is the unit you want to check if
local real yTo = GetUnitY(unit2) //the angle is less than 60 degrees difference
local real dx = xTo - xFrom
local real dy = yTo - yFrom
local real angle = Atan2(dy, dx) //the angle from unit1 to unit2
local real distance = SquareRoot(dx*dx + dy*dy) //the distance between unit1 and unit2
local real da = angle - GetUnitFacing(unit1) * bj_DEGTORAD

if da < 0 then
    set da = 0 - da //Get the absolute value of the difference between unit1's
                         //facing angle and the angle between unit1 and unit2
endif

if da < maxAngle and distance < maxDistance then
    return true
endif
return false
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