I’ve tried detecting edges yesterday and it worked (not very consistent with mouse placing though) except for the part on top of the cylinder, so I scrapped the code. But if theres multiple approach, i’d like to see and know how they work.
EDIT: Nevermind, I still have the code. But basically this is what I did.
if horizontalMode == "Stack" then
local nearestLog = hitPart
local logHeight = nearestLog.Size.Y
local stackOffset = Vector3.new(0, logHeight, 0)
local stackPosition = nearestLog.Position + stackOffset
logGuide.CFrame = CFrame.new(stackPosition)
logGuide.Orientation = nearestLog.Orientation
elseif horizontalMode == "Extend" then
local nearestLog = hitPart
local logSize = nearestLog.Size
local logPosition = nearestLog.Position
local logOrientation = nearestLog.Orientation
local topEndpoint, bottomEndpoint
local halfLength = logSize.X / 2
topEndpoint = logPosition + nearestLog.CFrame:vectorToWorldSpace(Vector3.new(halfLength, 0, 0))
bottomEndpoint = logPosition - nearestLog.CFrame:vectorToWorldSpace(Vector3.new(halfLength, 0, 0))
local mousePosition = mouse.Hit.Position
local distanceToTop = (mousePosition - topEndpoint).Magnitude
local distanceToBottom = (mousePosition - bottomEndpoint).Magnitude
if distanceToTop < distanceToBottom then
local directionToPlace = (mousePosition - topEndpoint).Unit
if math.abs(directionToPlace.X) > math.abs(directionToPlace.Z) then
if directionToPlace.X < 0 then
--print("top")
if nearestLog.Orientation.Y == 0 then
logGuide.CFrame = CFrame.new(topEndpoint - Vector3.new(-logSize.X/2,0,0))
logGuide.Orientation = Vector3.new(0, 0, 0)
else
logGuide.CFrame = CFrame.new(topEndpoint - Vector3.new(0,0,logSize.Z*2.5))
logGuide.Orientation = Vector3.new(0, 90, 0)
end
end
else
if directionToPlace.Z > 0 then
--print("left top")
if nearestLog.Orientation.Y == 0 then
logGuide.CFrame = CFrame.new(topEndpoint + Vector3.new(0, 0, logSize.Z*2.5))
logGuide.Orientation = Vector3.new(0, 90, 0)
else
logGuide.CFrame = CFrame.new(topEndpoint + Vector3.new(logSize.X/2, 0, 0))
logGuide.Orientation = Vector3.new(0, 0, 0)
end
else
--print("right top")
if nearestLog.Orientation.Y == 0 then
logGuide.CFrame = CFrame.new(topEndpoint - Vector3.new(0, 0, logSize.Z*2.5))
logGuide.Orientation = Vector3.new(0, 90, 0)
else
logGuide.CFrame = CFrame.new(topEndpoint - Vector3.new(logSize.X/2, 0, 0))
logGuide.Orientation = Vector3.new(0, 0, 0)
end
end
end
else
local directionToPlace = (mousePosition - bottomEndpoint).Unit
if math.abs(directionToPlace.X) > math.abs(directionToPlace.Z) then
--print("bottom")
if nearestLog.Orientation.Y == 0 then
logGuide.CFrame = CFrame.new(bottomEndpoint + Vector3.new(-logSize.X/2,0,0))
logGuide.Orientation = Vector3.new(0, 0, 0)
else
logGuide.CFrame = CFrame.new(bottomEndpoint + Vector3.new(0,0,logSize.Z*2.5))
logGuide.Orientation = Vector3.new(0, 90, 0)
end
else
if directionToPlace.Z > 0 then
--print("left bot")
if nearestLog.Orientation.Y == 0 then
logGuide.CFrame = CFrame.new(bottomEndpoint + Vector3.new(0, 0, logSize.Z*2.5))
logGuide.Orientation = Vector3.new(0, 90, 0)
else
logGuide.CFrame = CFrame.new(bottomEndpoint + Vector3.new(logSize.X/2, 0, 0))
logGuide.Orientation = Vector3.new(0, 0, 0)
end
else
--print("right bot")
if nearestLog.Orientation.Y == 0 then
logGuide.CFrame = CFrame.new(bottomEndpoint - Vector3.new(0, 0, logSize.Z*2.5))
logGuide.Orientation = Vector3.new(0, 90, 0)
else
logGuide.CFrame = CFrame.new(bottomEndpoint - Vector3.new(logSize.X/2, 0, 0))
logGuide.Orientation = Vector3.new(0, 0, 0)
end
end
end
end
end