• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Damage enemies that contact a 'link' between two units.

Status
Not open for further replies.
Level 24
Joined
Aug 1, 2013
Messages
4,657
If I understand it correctly, you have two units and a lightning in between them (a straight line).
If so, you could group all units inside a rectangle on that line and damage each unit in the group.

I dont know how you can group the units though.
Maybe Ill be making another group function.
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
An option would be to use math in this case. You can determine the distance of a point from line via various formulas.
First, you would need the formula for the line between the two units meaning you would need to create formula for line from two points (those two points = locations of both units).

Then you would need to pick all units, which are within [length of line /2] range from the center of the line.
Finally, iterate through each picked unit and check the distance of the unit from the line. If it is close enough for you (e.g. range 30 or less), that unit touched the line.

There are many tutorials on how to create a line from two points and how to determine the distance of a point from a line.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
JASS:
library IsPointInRectangle
    //determins if point P is in rectangle ABCD
    function IsPointInRectangle takes real ax, real ay, real bx, real by, real cx, real cy, real dx, real dy, real px, real py returns boolean
        local real cross0 = (py-ay)*(bx-ax)-(px-ax)*(by-ay)
        local real cross1 = (py-cy)*(ax-cx)-(px-cx)*(ay-cy)
        local real cross4 = (py-dy)*(ax-dx)-(px-dx)*(ay-dy)
        
        return ((cross0*cross1 >= 0) and (((py-by)*(cx-bx)-(px-bx)*(cy-by))*cross1 >= 0)) or ((cross0*cross4 >= 0) and (((py-by)*(dx-bx)-(px-bx)*(dy-by))*cross4 >= 0))
    endfunction
endlibrary

Might help.

All you have to figure out is what A, B, C and D are.
 
Status
Not open for further replies.
Top