Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

how would i find the edge of a part?

Asked by
Smauce 12
5 years ago

using a part's position and size, how would i be able to get one of the edge's world position?

1 answer

Log in to vote
3
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

As far as I know, there is no function or method that will give you the position of an edge.

You could, however, use some math to figure it out. Say we're working with regular rectangular parts. The ones that spawn in by default.

local part = Instance.new("Part")

I know that the Position of any BasePart is the coordinates of the center of the object. Using this, as well as the size, you could find the position of pretty much any location of the part.

For example, let's say we want to find the position that represents the center of the top surface. Our Part has the size 4x1x2. The y-component of the size is 1. Since the position of the part is located at the center, we could add half of the y component to get the top surface of the part.

local topSurfaceCenterPosition = part.Position + Vector3.new(0, (part.Size.Y / 2), 0)

Now say you wanted to get the right-most edge of the top surface. We could apply the same method by adding half of the size's x-component. (It's just a matter of knowing which axis corresponds to which side)

local topSurfaceRightEdge = topSurfaceCenterPosition + Vector3.new((part.Size.X / 2), 0, 0)
-- or, if you didn't define topSurfaceCenterPosition:
local topSurfaceRightEdge = part.Position + Vector3.new((part.Size.X / 2), (part.Size.Y / 2), 0)

If you wanted to get a specific corner, you could also add or subtract the Z component.

Things get a lot more tricky if your parts have an orientation that is not the default (0, 0, 0). If that's the case, let me know and I can try to dive deeper into that realm with you.

I hope what I'm leaving here is enough to help you out though.

0
this helped. thank you! Smauce 12 — 5y
0
no problem! glad I could help you out :) chomboghai 2044 — 5y
0
this help me too thanks! GalaxySMediaXz 32 — 3y
Ad

Answer this question