So as you can see when I rotate to a 45 degree angle it makes the wall a 45 degree angle, but I want it to be 90 degrees.
Script:
local rootCFrame = rootPart.CFrame
local angle = rootCFrame - rootPart.Position
local cframeTable = table.pack(angle:GetComponents())
for i, v in pairs(cframeTable) do
cframeTable[i] = math.round(v)
end
angle = CFrame.new(table.unpack(cframeTable))
visual:PivotTo(angle + hitPos)
You could try getting the rotation on the y, then dividing it by 90 and rounding it before then multiplying it by 90 again. idk if this would work my brain is tired
-- I forgot the how Luau handles modulo's negative case, this should probably work
function roundRotation(rotation, radians)
return (rotation - rotation % (2 * math.pi)) + rotation % radians
-- Edit: Alternative code: return math.round(rotation / radians) * radians
end
function roundCFrameOrientation(cframe, radians)
local rx, ry, rz = cframe:ToEulerAnglesXYZ()
return CFrame.fromEulerAnglesXYZ(roundRotation(rx, radians), roundRotation(ry, radians), roundRotation(rz, radians)) + cframe.Position
end
-- 90 degrees example:
local cframe = -- Your CFrame
local rounded = roundCFrameOrientation(cframe, math.rad(90))
I ended up finding a solution. I basically did what you did, but out of 1. How does it work? I don’t know. Why did I use half of pi? I don’t know. Just testing and it works.
Script:
local x, y, z = rootPart.CFrame:ToOrientation()
local dividant = math.pi / 2
y = math.round(y / dividant) * dividant
local newCFrame = CFrame.fromOrientation(x, y, 0) + hitPos
visual:PivotTo(newCFrame)