Hello. I’m trying to make my first plugin, like terrain editor. (but much better)
For now, I stuck with plane lock. As you know, in default terrain editor, you can see it - gridded plane, which will orient towards your camera by 45 degrees.

(how this looks on sphere:)

(for better understanding:)

workspace.CurrentCamera is lokated in the middle of this “sphere”. So I can get direction of look.
But My main problem consist of X and Z dimensions. IDK how to correctly count their direction in “45 degreed” positions:

But that’s not single problem that I have. IDK how correctly I should multiply rotations, and due to this, I receive weird rotation by 45-X and 45-Z degrees.

Can someone help me, and explain me, how I should make this grid correctly, bc I can’t solve this problem for 3 days.

The easiest way would be to loop over each of these directions, then check which one you’re closest to.

local directions = {}
-- build directions list (do just once at the start. Could also hardcode)
for x = -1, 1 do
for y = -1, 1 do
for z = -1, 1 do
if not (x == 0 and y == 0 and z == 0) then
table.insert(directions, Vector3.new(x, y, z).Unit)
end
end
end
end
local function SnapToNearest(vec, directions)
local snapped = nil
local biggestDot = -math.huge
for _, dir in directions do
local dot = vec:Dot(dir)
if dot > biggestDot then
biggestDot = dot
snapped = dir
end
end
return snapped
end

You could use that then like SnapToNearest(camera.CFrame.LookVector, directions) to get a new LookVector aligned to one of your points.