I need a calculation to get the position of a part (to align to the middle of a target)
This is what I want
This is how far I got
This is the code that I’m using
local function getPlacementPosition()
local target, hit, normal = mouse.Target, mouse.Hit, mouse.TargetSurface
local snappedNormal = target.CFrame:VectorToObjectSpace(normal)
local cframe = (
CFrame.new(
hit.X,
hit.Y,
hit.Z
) * CFrame.Angles(0, math.rad(target.Orientation.Y), 0)
) * CFrame.new(
((model.PrimaryPart.Size.X / 2) + (target.Size.X / 2)) * -snappedNormal.X,
0,
0
)
return cframe
end