I made a thing that defines polygons and tells you which one you’re inside. It runs really fast, so I put it in a renderstepped loop.
I have a folder with a bunch of nodes in it. The nodes are named after which zones they define the border of. If a node only defines the border of zone A, it is named “A.” If it is a vertex between zones A and B, its name is “AB,” etc. Each zone it is a part of the border of is in its name.
[strike]A table is created for each zone and the table is filled with each node on the border of that zone. The nodes in each table are then sorted radially around the center of the zone. This is the part that could certainly use improvement, because it doesn’t support concave shapes or shapes with holes because it won’t define the borders properly. The point-in-polygon raycasting algorithm expects that each next point in the list is adjacent to the last, and that the last is adjacent to the first, so that would need to be changed as well.[/strike]
edit: changed how it works. Nodes are now connected manually. Each node has a number inside of it, and inside that number is other numbers representing the nodes that it is connected to. Nodes are not connected both ways, make sure you don’t do that if you change it. Each connection acts as a border of a polygon. The point-in-polygon raycasting algorithm counts the number of intersections from the outside of the polygon to where you are, and if that number is odd, you are inside the polygon. In the example place, the yellow zone is a ring. The outer nodes are all labeled D, and the outer nodes of the inside are also labeled D because they are part of the yellow border. If you are inside the inner ring, though, the outer border is intersected as well as the inner border in order to reach you, so the number of intersections is even and you are not inside zone D.
added a couple more areas to the demo to demonstrate the capabilities. Inner square is inside of outer square, but the nodes that make up inner square are also defined as borders of outer square, so if you are inside inner square, you are “outside” the boundaries of outer square because there is an even number of borders between you and the outside.
It looks like accessing the character through player.CharacterAdded:wait() in the beginning of a local script in the PlayerGui always works, and just getting player.Character always gets the previous one. Is this always the case?
I made it FE and put the code on the server instead of on the client, and the client receives the area from the server whenever it changes. I also added a dark box that turns dark when you walk onto the platform.
This was inspired by Hexaria, because I don’t know how it knows if I’m in the healing zone or if I’m outside of it when I go around the gate over mountains as opposed to walking through it.
[strike]straight magic[/strike] I took the very simple (and possibly buggy) route when implementing this. Literally just gigantic, invisible, anchored parts that use the touched event
EDIT: I worded that a little poorly. I have not experienced any bugs with this, due to the fact that the game restricts transportation (i.e no flying or anything). The method does not seem to be that safe, and it’s restricting in that you must either define your zones in a linear manner, or you would have to be extremely careful to avoid overlapping buffers if it were multi-dimensional. We will be ditching this method soon most likely, Hexaria world structure is undergoing some big changes