Calculating Two Corners

Hello! I’m currently looking to calculate the position of two corners of a part in order to then use it in a region3!

Here’s the locations I’m looking for (or something similar)

The red points are the corners I’d be looking to get.
Anyone have any idea’s on something like this?

1 Like

I believe it’s:

local bl = part1.Position-part1.Size/2
local tr = part1.Position+part1.Size/2

Otherwise try messing around with:

local bl = part1.Position-Vector3.new(part1.Size.X/2,part1.Size.Y/2,part1.Size.Z/2)
local tr = part1.Position-Vector3.new(-part1.Size.X/2,-part1.Size.Y/2,-part1.Size.Z/2)

Try adding ‘-’ or removing them.

Hope this helps!

2 Likes
local bottom_left = part.Position - (part.Size/2)
local top_right= part.Position + (part.Size/2)

Aside from the solutions previously stated, keep in mind that if your part is rotated in any way, you’ll get incorrect results if you want those results to always be the part’s corners. So always keep that part’s rotation in world space. :slight_smile:

3 Likes

Also keep in mind that Region3s are always axis aligned, meaning they can’t be rotated. If you need similar functionality but with rotation, search for “rotated region3”, there’s a free model somewhere that works very well.

1 Like

This should also keep the rotation:

local bl = part1.CFrame * CFrame.new(part.Size.X/-2,part.Size.Y/-2,part.Size.Z/-2)
local tr = part1.CFrame * CFrame.new(part.Size.X/2,part.Size.Y/2,part.Size.Z/2)

Ofcourse, with region3 it won’t help much but it gets the corners for rotated bricks.

Using the equations provided I am presented with the same thing that has happened on my attempts.

https://gfycat.com/HeartyLittleEyelashpitviper

This does need to work with rotation on the… Y I believe

1 Like
local part = script.Parent
while wait(.5) do
   local bl = part.CFrame * CFrame.new(part.Size.X/-2,part.Size.Y/-2,part.Size.Z/-2)+Vector3.new(.05,.05,.05)
   local tr = part.CFrame * CFrame.new(part.Size.X/2,part.Size.Y/2,part.Size.Z/2)-Vector3.new(.05,.05,.05)
   local reg = Region3.new(bl.Position,tr.Position)
   print(#game.Workspace:FindPartsInRegion3WithIgnoreList(reg,{part})) --make sure your model is also in the ignore list!
end

This seems to work for me.

This is the test place I used:
example.rbxl (13.2 KB)

1 Like

https://gfycat.com/NaturalAshamedEider Strange…

1 Like

You can actually simplify this to

local bl = part1.CFrame * -part.Size
local tr = part1.CFrame * part.Size

which should give the position of the corners in world space. :wink:

4 Likes

If you’re not getting correct results from what was stated, it’s probably because you’re not handling rotations correctly. Are you sure you’re creating the region3 correctly? You should probably look into when you’re creating the rotation for the model’s final position because if it’s before the offset (the grid placement relative to the origin of the grid, which is probably the center of that part there) then what’s happening is your position starts at the origin, rotates, then offsets itself which is incorrect.

Also, from there you can just give up on using region3s if you want cuboid hitboxes and just use math, which is easier. :smile:

1 Like

From what he linked, I think he wasn’t using relative space to the cframe…

I showed how to make an AABB suitable for use in creating a Region3 here:

It has a function to create the AABB from a part, and also extend it when you want to add more parts to that AABB.

2 Likes