Detecting edges of a part

Hello there! I have made a edge detecting system, but it is rather simple, as it can only detect parts that are rectangles, and are not rotated.

You can have a look at my effortless endeavor on this:
The system works fine, but it has many many flaws, such as it cant detect the edges of a rotated part, or wedges. Furthermore, you have to be aiming at the sides of a part, if you are on top of a part, it wont do anything, as seen here:

Is there any ways to make the system overall functions better ?

This is the code:

local indicator ="Part", workspace)
indicator.Shape = "Ball"
indicator.Anchored   = true
indicator.Material   = Enum.Material.Neon
indicator.BrickColor ="Bright red")
indicator.CanCollide = false

	local ray       =, camera.CFrame.LookVector * 300)
	local part, pos = workspace:FindPartOnRayWithIgnoreList(ray, rayIgnore)
	if part then
		if part:IsA("Part") and not part:IsA("MeshPart") then
			pos =, part.Position.Y + part.Size.Y/2, pos.Z )

			indicator.Position = pos				

Any help is appreciated!

You should make separate parts added manually as “detection” boxes.

this is cause your not doing it as local let me explain so if a part is rotated its Y would appear at top aka global to make it local use CFrame.UpVector That may help

1 Like

Hi, thanks for your reply, but what are detection boxes like you have mentioned above ?

add the detection thing as parts…

I do not know what rayIgnore contains, but make sure that indicator is in it. Otherwise, the raycast might continuously hit the indicator.

Try to set the CFrame instead. Setting the position might affect the actual placement of the indicator by offsetting it in the vertical direction.

This will make the indicator always show up on top. I assume that you want it to land on the closest edge to the player?

1 Like

I added the indicator into the params, and it will now not move rapidly when I am looking down at another part

Yes, I want it to land on the closest edge to where the camera is looking at.

1 Like

Do you want the red circle to find the nearest edge of the part to the mouse, or the “highest” edge. What’s the deal here?

Also you said you want this to work with other shapes. Will all these shapes be convex? Will these shapes be meshes / models?

I want it to find the nearest edge, the problem with my system currently, is that it only work when you are looking at the side of a part, due to to this pos =, part.Position.Y + part.Size.Y/2, pos.Z ) But when I am on top of the part, however, it wont detect any edges, as seen here:

I mainly desire for it to work with normal parts and wedges