How roblox calculates the normal vector of a ray

Hello everybody, the question is pretty self explanatoray, any raycast has a property called Normal
wich return a vector perependicular to the surface that the ray has collided with i just wanted to know how this works under the hood and how roblox calculates it

1 Like

It is done by analyzing the geometry of the surface at the collision point.

For example:

For a flat surface (like a part), the normal is straightforward. If the surface is horizontal, the normal might be Vector3.new(0, 1, 0), pointing straight up.

For more complex surfaces (like meshes or terrain), the normal is calculated based on the local geometry. This involves mathematical operations like cross products of the surface’s edges to find a perpendicular vector.