Region3 Signals

Region3. The hardest thing in my opinion to script. Well, depends what you want to do with it.

I have an idea. If a part (called Glider) is in a certain region, a part is red and as soon as the “Glider” part comes out of the region it turns green.

I’ve no idea where to start. I had a crack at this back in September and again in February and most recently a few days ago but I just can’t get it to work. If this becomes possibly for me, it’ll open up a number of possibilities .

Let me explain:

“Signal” part is green.

“Glider” enters a Region.

While “Glider” is in this Region, the part is red.

When “Glider” leaves Region, the part turns green.

If anyone can help I’ll be super happy :slight_smile:

Region3 is actually very easy, I actually use a Module called “RotatedRegion3” made by EgoMoose because the normal Region3 constructor doesn’t support rotation at all, so the RotatedRegion3 module simulates a rotated version with ez hard core maths, right so you want to make a system where if a Part is in a certain Region, the Part will be Red and when it comes out it’ll turn green. First, lets require the module “RotatedRegion3” so we can have Rotation applied. You don’t need any knowledge about what the code does in the RotatedRegion3 Module, all you need to know is how to use the functions properly.

Here is the module which you can Download, once you have inserted it into Studio proceed with the following…

Make a Script that references the RotatedRegion3 like so:

local Storage = game:GetService("ReplicatedStorage")
local RotatedRegion3 = require(Storage:WaitForChild("RotatedRegion3"))

Alright so here we have defined our RotatedRegion3 module, now lets get to the actual system!

The main functions of the RotatedRegion3 module we will be using will be RotatedRegion3.new() and RotatedRegion3:cast()

local GliderPart = workspace:WaitForChild("Glider")
local HitBox = RotatedRegion3.new(CFrame.new(10, 0, 10), Vector3.new(20, 20, 20))

So we have Defined HitBox as RotatedRegion3.new() Usually any Module that has a .new() function is called a Constructor, CFrame.new(), Vector3.new() etc.
RotatedRegion3.new() takes in two arguments, a CFrame & a Size. The Size determines how big the Region will be, the CFrame determines the location & rotation.

Also, lets make something called an IgnoreList before we proceed to make the code that detects if something intersects the Region3, an IgnoreList in this scenario requires a Table with a list of objects you want to ignore while detecting if a Object has intersected the Region3.

local IgnoreList = {workspace:WaitForChild("Baseplate")}

You can add more Objects to the table to, just separate them using commas. Also an IgnoreList is optional aswell.

local Intersected = false

for i,v in pairs(HitBox:cast(IgnoreList, 100) do
    if v == GliderPart then
       Intersected = true
       GliderPart.BrickColor = BrickColor.Green()
       break
    end
end

The Cast function takes in two arguments, a IgnoreList and the amount of parts you want to detect, and that’s pretty much it for this. This is just the basic system of detecting a Part in a region3, I can’t cover the rest of your request since I’m low on time right now, if I got anything wrong please let me know and I’ll be happy to correct myself. If you’re confused on anything I will reply in sometime.

3 Likes

The Glider doesn’t turn green, it’s a separate part in the workspace called “Aspect”

function isInRegion3(region, point)
 local relative = (point - region.CFrame.p) / region.Size
 return -0.5 <= relative.X and relative.X <= 0.5
 and -0.5 <= relative.Y and relative.Y <= 0.5
 and -0.5 <= relative.Z and relative.Z <= 0.5
end

Use this function to constantly check if the part’s Position is in the Region3, and if it’s in the Region3 it turns red. I’ll leave the rest of the script to you. Hope I could help! :slight_smile:

https://developer.roblox.com/en-us/api-reference/function/Workspace/FindPartsInRegion3

Should be pretty much everything you need to get started.

My mistake but you can apply my ideology of the Region3 to that part, Names don’t matter.

but the “Aspect” part is in a model called “Signal” in workspace…