Is it possible to detect edges of parts?

Im curious to know if it is possible to detect edges.

1 Like

It’s possible, with a little bit of math. Here’s an example of getting the top of a part. With some more math, you can get the edges of it as well.

local Part = Instance.new("Part")
Part.Size = Vector3.new(5,5,5) -- Half of this size is 2.5 remember this
Part.Position = Vector3.new(0,0,0) -- We set the position to the very center of our game
local Origin = Part.Position -- We want the origin of the part now
local TopSurface = Origin + Vector3.new(0,Part.Size.Y/2,0) -- Now we use the part's size (5), and add it to the Y axis.
2 Likes

This is not always the case. Once the part is angled, you need to focus on which way is the normal up, left and forward. CFrame would be in place of this and those details to focus on is LookVector, UpVector and RightVector. Please note that this only applies to parts that are block-shaped and not irregular like a ball.

Once you have these properties, you can multiply the aforementioned vectors with each vector in size of the part to the corresponding property.

I think in that case you’d want to use UpVector, RightVector, and LookVector to get the same positions. And I’m not sure if it uses the same method but multiplying each vector by the size would likely still have the same results you’d expect.

The only problem I really see with this method is the fact that I’m not sure how I’d do it with any part close to the players character. Perhaps raycasting?

Oops, it’s half the size in each direction. Don’t forget that you can use the negative value of LookVector and everything else for its opposite direction.

If you’re making a ledge grabbing system, there are a pretty good amount of tutorials on how to do this. Getting the edge of a part from where your character is depends on raycasting, region3, or touched. You could use either of those, but it’s most recommended that you’d want to use raycasting for ledge grabbing mechanics.

Once you get the edge of your part, you’ll want to compare that edge to either your head, or your lower body position to check if the magnitude of both positions from the Y axis is close enough to be considered capable of ledge grabbing.

Now after this, there is also a raycasting property, which is labeled ‘Normal’. This will get the direction of the surface of what part your ray has returned.

Alright fair enough I’ll try that then