Surface normal help

The third value that FindPartOnRay() returns, is the surface normal of the area that was hit. You can use this to orientate your spray paint part’s orientation to match the orientation of the hit surface.

Some example code:

local hit, pos, normal = game.Workspace:FindPartOnRay(ray) --normal is a vector that points in a certain direction
	    
local SprayPaintPart = game.ServerStorage.SprayPaintPart:Clone()
SprayPaintPart.Parent = workspace
SprayPaintPart.CFrame = CFrame.new(pos, pos + normal) --calculate the LookAt Vector by adding the hit position to the normal directional Vector

The “normal” value is a directional Vector3 with a magnitude of 1, otherwise known as a unit Vector, which basically means that it points in a certain direction to the extent of one stud.
Some information on directional Vectors:

For example, you could get the LookVector of a CFrame, and use it to extent a part in that direction.

LookVector = Part.CFrame.LookVector
Part.Position = Part.Position + LookVector * 10 --this would move the part forward 10 studs, forward being the front face direction of the part

--there are many uses for directional Vectors, but this is just an example
11 Likes