# Help finding 2 vectors orthogonal to a surface normal

To avoid misunderstanding, I need help finding 2 vectors orthogonal to the surface normal of a Raycast/Basepart, and the main problem is that I don’t know which 2 vectors to use.

You could use an implicit equation then see which vector closely matches to that. Given what you describe the vector which is orthogonal is actually something i recognize from computer graphics, its the ray plane equation.

``````0=normal:Dot((o+d*t) - pointOnSurface)
``````

That works out to like (from my raytracer)

``````float calcScalarPlane(Ray ray, Plane plane) {
float t = dot(plane.normal, plane.point - ray.origin) / dot(plane.normal, ray.direction);
if (t > EPSILON) {
return t;
} else {
//didnt hit
return -1.0;
}
}
``````

Or in lua like maybe (havent tested)

``````local function calcScalarPlane(o,d,n,p)
local t = n:Dot(p - o) / n:Dot(r)
local returnState = false
if t > 0.001 then
returnState = true
else
t = -1 --prevent -inf stuff
end
return returnState, math.acos(n:Dot((o+d*t) - o))
end

local r, a = calcScalarPlane(hrp,lookvector,normal, pointOnNormal)
if r then
print(a)
end
``````

Just do that for all the normal vectors of the player (make sure they unit vectors)

1 Like