Need help creating regions from one point to another in a straight with an AOE radius

Exfyre

hmm...
Reaction score
60
As the title says, I'm adding rects to a region in small amounts in order to form a straight line from one point to another based on the units' distances and specified Area of effect.


2iqg6li.jpg



I've changed this so many times that I don't even know what I'm looking at anymore.

My code:
assume
AOE = 25
RADIUS = 1000
Code:
            set xt = 0
            set yt = 0
            set dx = x2 - x1
            set dy = y2 - y1
            set dist = SquareRoot(dx * dx + dy * dy)
            set o = 0
            loop
                set o = o + 1
                if x1 < x2 and y1 < y2 then
                    set xt = xt + dx/dist
                    set yt = yt + dy/dist
                endif
                if x1 > x2 and y1 < y2 then
                    set xt = xt - dx/dist
                    set yt = yt + dy/dist
                endif
                if x1 < x2 and y1 > y2 then
                    set xt = xt + dx/dist
                    set yt = yt - dy/dist
                endif
                if x1 > x2 and y1 > y2 then
                    set xt = xt - dx/dist
                    set yt = yt - dy/dist
                endif
                call RegionAddRect(rr, Rect(x1+xt*RADIUS-AOE/2, y1+yt*RADIUS-AOE/2, x1+xt*RADIUS+AOE/2, y1+yt*RADIUS+AOE/2))
                exitwhen o == dist
            endloop
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
This should help you grasp the concept. I would use this method to do it.
 

Attachments

  • rects.JPG
    rects.JPG
    41.1 KB · Views: 121

Exfyre

hmm...
Reaction score
60
thank you! That diagram did help. I had forgotten about angles.:thup::thup:
+rep
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top