The video above shows my building system. I need help fixing the collisions on my build system. I’ve tried using normals, and I’ve made a little progress on it (as seen in the screenshot below)
Here is my script: (PreviewObject is the green object in the video)
run.RenderStepped:Connect(function(dt)
if PreviewObject and mouse.Target then
local GoalPosition = mouse.Hit.Position
local MyParams = RaycastParams.new()
MyParams.FilterType = Enum.RaycastFilterType.Include
MyParams.FilterDescendantsInstances = {mouse.Target}
local PositionResult = workspace:Raycast(cam.CFrame.Position, (mouse.Hit.Position - cam.CFrame.Position).Unit * 1000, MyParams)
if PositionResult then
GoalPosition += PositionResult.Normal
print(PositionResult.Normal)
end
Yes, but the script above is the only part of the script which determines the position of the part in game, and I’m not sure how the entire script will help
run.RenderStepped:Connect(function(dt)
if PreviewObject and mouse.Target then
local GoalPosition = mouse.Hit.Position
local MyParams = RaycastParams.new()
MyParams.FilterType = Enum.RaycastFilterType.Include
MyParams.FilterDescendantsInstances = {mouse.Target}
local PositionResult = workspace:Raycast(cam.CFrame.Position, (mouse.Hit.Position - cam.CFrame.Position).Unit * 1000, MyParams)
if PositionResult then
GoalPosition += PositionResult.Normal
print(PositionResult.Normal)
end
PreviewObject.CFrame *= CFrame.new():Lerp(PreviewObject.CFrame:ToObjectSpace(CFrame.new(RoundVectorToNearestNumber(GoalPosition, BuildingIncrement)) * PreviewObjectRotation), (1 - math.pow(2, -35 * dt)))
PreviewObject.Color = Color3.fromRGB(94, 255, 83)
PreviewObject.Transparency = 0.5
PreviewObject.CanCollide = false
PreviewObject.CanQuery = false
PreviewObject.Anchored = true
end
end)
Edit: The lerp part at the bottom is just a way to make the part smoothly transition to wherever I want it to be at. It sets the CFrame of the PreviewObject to wherever the GoalPosition is