• 🏆 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!

[General] Tiny rects

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
I need kind of a precise way to detect whenever a unit enters a really small area. Is it possible to set a rect to lower than 32x32?
Yes it is possible. I do not think there is a limit as to how small a rect can be.

However be aware the unit enters/exits region event uses a region and not a rect. Regions work in map cells so the smallest region one can represent is 32x32 units.
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
Yes it is possible. I do not think there is a limit as to how small a rect can be.

However be aware the unit enters/exits region event uses a region and not a rect. Regions work in map cells so the smallest region one can represent is 32x32 units.
That was a pretty roundabout way to say "No. Watch the terms you are using..." :|

I guess you could have a region around the area you need and when a unit enters it start your own box collision checking if the coordinates of the unit correspond with the coordinates of the tiny area.

@Dr Super Good Would that work, or ?


-Ned
 
Level 11
Joined
Oct 16, 2013
Messages
246
So rects can effectively have any size but now I can't find the way to prevent the leak when setting the point in 'Unit enters rect' event. Am I doing something wrong? For now, I'm using 'A unit comes within X of' along with invi dummies and I haven't found any bug... yet.

Thanks for the help.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
So rects can effectively have any size but now I can't find the way to prevent the leak when setting the point in 'Unit enters rect' event. Am I doing something wrong?
Sounds like it since the even does not even take a location object to leak...
Well, my unit is fixed to vertical/horizontal rails and there's a region in every intersection where it can make 90-degree turns after stepping over. 32x32 is not small enough to make the rail change smooth.
This is usually done by state machine of sorts. When entering a corner you use different movement logic than when going along straights, the movement is in a different state then.
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
The solution without region enters or 'in range' events is to use a low-timeout (<0.5s) repeating timer that compare's the unit's coordinates to the min and max x/y coordinates of each rect. Store all the rest edges in arrays at map init and it won't be a memory hog, just real number comparison. You can turn the timer off when no units are moving.

JASS:
//pseudocode, you can do this in GUI
loop through all such units you want to check, using index1 as counter
    Set U = units[index1]
    Set UX = X coordinate of U
    Set UY = Y coordinate of U

    loop though rects using index2 as counter
        Set mx = rectsmx[index2] //min x
        Set Mx = rectsMx[index2] //max x
        Set my = rectsmy[index2] //min y
        Set My = rectsMy[index2] //max y
        //There are functions to get these min and Max coords in jass, may have to look to locactions to do it in GUI

        if (UX <= Mx) and (UX >= mx) and (UY <= My) and (UY >= my) then
            //The index1'th unit is in the index2'th rect
            //Do whatever here
        endif
    endloop
endloop
 
Status
Not open for further replies.
Top