Ad
Log in to vote
0

How to insert a region 3 in the same position and at the same size as a part?

Asked by 3 days ago
Edited 3 days ago

Ive been looking for a way to put a Region3 in the position of a part, and In my search I found this

local RegionPart = game.Workspace.RegionPart
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.Size / 2)

local Region = Region3.new(pos1, pos2)

And, im just wondering how that actually works. How does that get the corners of a part?

1 answer

Log in to vote
1
Answered by
imKirda 2679 Moderation Voter Community Moderator
3 days ago

Uh well alright, i did not want to go into this complicated for me math but i will try to explain it. Roblox regions they need top left and bottom right vectors of the region to make it work, in wiki it says Min and Max.

The way how it works is that Position property in Roblox returns position of the part's center, here is image of what i mean. Now Size returns the part's size but since we have the middle position, we don't need to add whole size to the position because our position is in middle, that's why you divide it by 2 to get the edge. Here is illustration of what i mean.

Now since we need the Min position, we substract half size of the part from the position which gets you bottom left corner. To get the top right corner however, you just need to add to the part's size. Here if final image that i can show you, it does not count the Y axis, but it's the same.

the grey cube in the images is the part

Ad

Answer this question