Hi, I have searched through many other similar topics with no avail.
What I am trying to achieve is to get the direction of surface (right, top, front, etc.) with something like Mouse.TargetSurface. To place an object parallel to something like a wall.
Simply, I am making a placement system that attaches a part smoothly to a wall.
I would go about it by determining the direction with the greatest dot product with the normal. If you want to get the normal * direction, you can just do:
I have the dot product. But how would I convert that to a parts orientation?
local raycastResult = game.Workspace:Raycast(Mouse.UnitRay.Origin, Mouse.UnitRay.Direction * 50)
if raycastResult then
local Normal = raycastResult.Normal
print(Normal:Dot(Mouse.UnitRay.Direction))
else
print("false")
end
It would actually probably less expensive and less complex to just get the greatest (with absolute value) component of the normal vector and use that as the direction.
local normalDict = {
["X"] = normal.Unit * Vector3.new(1, 0, 0);
["Y"] = normal.Unit * Vector3.new(0, 1, 0);
["Z"] = normal.Unit * Vector3.new(0, 0, 1);
}
for axis, value in pairs(normalDict) do
local sign = math.sign(value[axis])
if value[axis] * sign > math.sqrt(3)/3 then
local primaryAxis = value.Unit
end
end