Face normal added to raycasting methods

The current raycasting methods provide two details: The part that was hit and the the position.

When we only had a few simple shapes it was easy to get whatever information we need about where a point hit, what face it hit on, the normal of the face, etc. It only took a bit of math.

With the introduction of solid modeling we are now missing some of the data we would need to do this. This could be solved by something as simple as returning the surface normal of the face the ray hit, or as complicated as adding multiple new classes to represent faces, edges, and points a ray could hit that may be incorporated into a solid modeling API in the future.

Regardless of how it’s done, we’re missing some information that would be very useful to have. This suggestion is simply that raycasting returns that information somehow.

Old post:

The current raycasting methods provide two details: The part that was hit and the the position.

Until recently this was enough to get all the face details one needs. While at that point face details automatically returned would have been great, they were not required. Those details could be done manually though Lua.

With the introduction of Solid Modeling, we can no longer figure out all face details within just RBX.Lua. While APIs to deal with unions, their faces, and their points would be incredibly useful and solve this problem, it’d still be slower and a lot more work than if it was done on the C side.

My suggestion is to add a CFrame (or a similar object to tell direction) as the 3rd result of FindPartOnRay and FindPartOnRayWithIgnoreList. This CFrame would be located at the center of whatever face was hit and face outwards from the face.

Edge cases (literally): When a ray hits an edge, perhaps one of the two faces could be chosen or maybe something completely different. If ROBLOX decides to go with something like this I’m sure they can think up a better way to do it. I’m just proposing the idea because I feel the new trouble with unions needs to be addressed.

TL;DR: Something like this

local part, position, faceNormal = Workspace:FindPartOnRay(Ray.new(Vector3.new(0,0,0),Vector3.new(0,0,10)))

Thanks to AxisAngle for suggesting normals instead of CFrames. Even if it returned a CFrame, it’d still be a normal so calling it a normal gets straight to the point.

[quote] The current raycasting methods provide two details: The part that was hit and the the position.

Until recently this was enough to get all the face details one needs. While at that point face details automatically returned would have been great, they were not required. Those details could be done manually though Lua.

With the introduction of Solid Modeling, we can no longer figure out all face details within just RBX.Lua. While APIs to deal with unions, their faces, and their points would be incredibly useful and solve this problem, it’d still be slower and a lot more work than if it was done on the C side.

My suggestion is to add a CFrame (or a similar object to tell direction) as the 3rd result of FindPartOnRay and FindPartOnRayWithIgnoreList. This CFrame would be located at the center of whatever face was hit and face outwards from the face.

Edge cases (literally): When a ray hits an edge, perhaps one of the two faces could be chosen or maybe something completely different. If ROBLOX decides to go with something like this I’m sure they can think up a better way to do it. I’m just proposing the idea because I feel the new trouble with unions needs to be addressed.

TL;DR:

local part, position, faceCFrame = Workspace:FindPartOnRay(Ray.new(Vector3.new(0,0,0),Vector3.new(0,0,10))) --faceCFrame is located at the hit face's center and faces outwards. --Useful for getting face details for unions. [/quote]

What you need is a normal. Not a CFrame.