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.