So, its pretty straight forward. I am trying to make a classic styled building system, but there seems to be a problem with placing models on tilted parts.
Basically, I am trying to get the model to snap on to parts and surfaces perfectly via CFrame and surfaces (normal). But I cannot for the life of me get this model to line up correctly with tilted surfaces.
Iv’e tried using CFrame:ToEulerAnglesYXZ() and CFrame:ToEulerAnglesXYZ(), but none of them seems to work.
Some help would be greatly appreciated!
local function MovePreviewModel(MouseTarget, MouseHit)
if MouseTarget then
if PreviewModel.Parent ~= PlayerCamera then
PreviewModel.Parent = PlayerCamera
end
local PrimaryPart = PreviewModel.PrimaryPart
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Blacklist
Params.FilterDescendantsInstances = {unpack(GetPlayerCharacters()), PreviewModel}
local UnitRay = workspace.CurrentCamera:ScreenPointToRay(Mouse.X, Mouse.Y, 1)
local BuildRay = workspace:Raycast(UnitRay.Origin, UnitRay.Direction * 1000, Params)
if BuildRay then
local HitPart = BuildRay.Instance
if HitPart then
local HitCFrame = CFrame.new(BuildRay.Position, BuildRay.Position + BuildRay.Normal)
PreviewModel:SetPrimaryPartCFrame(HitCFrame * CFrame.Angles(math.rad(-90), 0, 0) * CFrame.new(0, PreviewModel.PrimaryPart.Size.Y/2, 0))
end
end
end
end