Update: This module has served its purpose, but with the release of the new spatial query API this post is obsolete. It will be left untouched for learning purposes, but it’s strongly recommended to check out the built-in api solution instead.
Recently I took another crack at an old module I wrote some time back. The goal of this module is to provide users with a way to create Rotatable Region 3’s which is useful for too many reasons to list.
Even though this module (older versions) has been floating around for some time I figured I’d post on the devforum with this latest, and hopefully last, release
So what does this module allow you to do?
Basically, you the dev provide a CFrame
, Size
, and shape and the module allows you to do all the fun stuff you’d normally do with Region3’s for finding parts, but allowing for rotation.
Now something I just alluded to above is that you get to pick the shape! That means with this module you are not limited to boxes. You can create Rotated Region 3’s with the following shapes:
- Blocks
- Wedges
- CornerWedges
- Cylinders
- Balls
Here are some images of those different shapes being used for those interested:
Aside from the standard FindPartsInRegion methods you’re familiar with the RotatedRegion3 objects also pack methods for checking if individual points and parts collide with the region0.
If you’re interested the documentation you can find that here, but note it’s also included in the module itself:
--[[
API:
Constructors:
RotatedRegion3.new(CFrame cframe, Vector3 size)
> Creates a region from a cframe which acts as the center of the region and size which extends to
> the corners like a block part.
RotatedRegion3.Block(CFrame cframe, Vector3 size)
> This is the exact same as the region.new constructor, but has a different name.
RotatedRegion3.Wedge(CFrame cframe, Vector3 size)
> Creates a region from a cframe which acts as the center of the region and size which extends to
> the corners like a wedge part.
RotatedRegion3.CornerWedge(CFrame cframe, Vector3 size)
> Creates a region from a cframe which acts as the center of the region and size which extends to
> the corners like a cornerWedge part.
RotatedRegion3.Cylinder(CFrame cframe, Vector3 size)
> Creates a region from a cframe which acts as the center of the region and size which extends to
> the corners like a cylinder part.
RotatedRegion3.Ball(CFrame cframe, Vector3 size)
> Creates a region from a cframe which acts as the center of the region and size which extends to
> the corners like a ball part.
RotatedRegion3.FromPart(part)
> Creates a region from a part in the game. It can be used on any base part, but the region
> will treat unknown shapes (meshes, unions, etc) as block shapes.
Methods:
RotatedRegion3:CastPoint(Vector3 point)
> returns true or false if the point is within the RotatedRegion3 object
RotatedRegion3:CastPart(BasePart part)
> returns true or false if the part is withing the RotatedRegion3 object
RotatedRegion3:FindPartsInRegion3(Instance ignore, Integer maxParts)
> returns array of parts in the RotatedRegion3 object
> will return a maximum number of parts in array [maxParts] the default is 20
> parts that either are descendants of or actually are the [ignore] instance will be ignored
RotatedRegion3:FindPartsInRegion3WithIgnoreList(Instance Array ignore, Integer maxParts)
> returns array of parts in the RotatedRegion3 object
> will return a maximum number of parts in array [maxParts] the default is 20
> parts that either are descendants of the [ignore array] or actually are the [ignore array] instances will be ignored
RotatedRegion3:FindPartsInRegion3WithWhiteList(Instance Array whiteList, Integer maxParts)
> returns array of parts in the RotatedRegion3 object
> will return a maximum number of parts in array [maxParts] the default is 20
> parts that either are descendants of the [whiteList array] or actually are the [whiteList array] instances are all that will be checked
RotatedRegion3:Cast(Instance or Instance Array ignore, Integer maxParts)
> Same as the `:FindPartsInRegion3WithIgnoreList` method, but will check if the ignore argument is an array or single instance
Properties:
RotatedRegion3.CFrame
> cframe that represents the center of the region
RotatedRegion3.Size
> vector3 that represents the size of the region
RotatedRegion3.Shape
> string that represents the shape type of the RotatedRegion3 object
RotatedRegion3.Set
> array of vector3 that are passed to the support function
RotatedRegion3.Support
> function that is used for support in the GJK algorithm
RotatedRegion3.Centroid
> vector3 that represents the center of the set, again used for the GJK algorithm
RotatedRegion3.AlignedRegion3
> standard region3 that represents the world bounding box of the RotatedRegion3 object
--]]
You can find the module here:
Hopefully there aren’t any bugs, but if there are please let me know so I can fix and update them
Enjoy!