I need to detect and edge of a part from the mouse position, how would I go about doing that exactly, here is a reference image.
Raycasting would problably get u there.
Every time a player moves there mouse u could make a ray and if the ray hits the edge of the part u could do whatever u want.
Yeah but im asking how do I calculate it, there is no function for getting the edge.
Using rays?, if the ray hits the edge then u could say whatever u want?
The ray doesnt know if the edge is hit, it only returns what it hit and the position and the surface normal
So if the ray hits the position of the edge then u could do whatever u want…
The ray will stay active until it hits the edge of the position u want it to hit
Yeah but I would have to have a part at every edge, which is not the way I want to do it…
No, put a part at the edge and measure the position then delete it, in ur script say if the ray hits the position the part was at then so on…
Thats still very inefficient because if I have parts that are not the same size illl have to do that for every single part, also I doubt that would work properly
Duplicate the parts?, just scale it to your needs then if the ray hits the position the part was at then so on…
I dont think your understanding what Im trying to achieve, basically I want to get the edge of a part from my mouse position without the need of making parts
@ThoseNamesAreGood Raycasting will help, but not without the use of the surface normal. You can use the surface normal returned to determine the corner.
Hm, could you explain further please
The normal is a vector perpendicular to the tangential surface returned during a raycast operation. For example, (0, 1, 0) is an up vector, (0, -1, 0) is a down vector. You can use the returned normal to get an angle.
Alright but after that what do I do with that angle?
You want to detect the edge, so you can use the angle to determine if the surface is an edge.
Could you give an example of this at least your kinda of just throwing stuff at me
I do not think you can use a normal of or deduce the angle to help figure out if you hit an edge. An edge isn’t part of a face anyways, it defines a face, so it’d be impossible to actually “hit” the edge literally. You’d need to give a range from 0 to X
(like 0.01) studs away from the edge to define as the edge.
Basically, if you’re trying to figure out which edge of a part a Vector3 is closest to, I would do something like this:
- Get the position in object space - use
local localPos = Part.CFrame:ToObjectSpace(mousePosition).p
for that - Check the components of that vector.
- (for example) If
localPos.X
is close toPart.Size.X / 2
, then you’re on the right-side face. IflocalPos.Y
is also close to-Part.Y / 2
, then you’re also on the bottom-side face. Hurray! Now you know you’re on the right-bottom edge!
This would work just fine. This way, you can set a tolerance of what is accepted as the edge and what is not.