Hi. I have made a wall building system like bloxburg. Mine however snaps on to the nearest 90 degrees. I need a bit of help because it works fine however there is a gap in the corners. I think this is something to do with the distance between the two poles. Here is my code:
local ray = Ray.new(PositionA, (PositionA - PositionB).unit * Mag)
local part, position,normal = workspace:FindPartOnRayWithIgnoreList(ray, returnIgnoreList())
local distance = (PositionA - position).magnitude
--beam.Size = Vector3.new(ReplicatedStorage:FindFirstChild(Item).Size.Z, 10, distance)
local End = PositionB
local Start = PositionA
local Distance = (End - Start).Magnitude
Mouse.TargetFilter = beam
local units = {
[2] = Vector3.new(1, 0, 0);
[3] = Vector3.new(1, 0, 0);
[4] = Vector3.new(0, 0, -1);
[5] = Vector3.new(0, 0, -1);
[6] = Vector3.new(-1, 0, 0);
[7] = Vector3.new(-1, 0, 0);
[8] = Vector3.new(0, 0, 1);
[1] = Vector3.new(0, 0, 1);
}
local function get_Beam_CFrame(origin_Pos, end_Pos)
local delta_Pos = end_Pos - origin_Pos
local radians = math.atan2(delta_Pos.X, delta_Pos.Z) + math.pi
local degrees = math.deg(radians)
local unit_Index = math.ceil(degrees/45)
local distance = delta_Pos.Magnitude
local look_Pos = origin_Pos + units[unit_Index]
local beam_CFrame = CFrame.new(origin_Pos, look_Pos) * CFrame.new(0, 0, distance / 2) + Vector3.new(0,5,0)
return beam_CFrame
end
beam.CFrame = get_Beam_CFrame(Start,End)
beam.Size = Vector3.new(1,10, Distance)
BeamCFrame = beam.CFrame
BeamSize = beam.Size
TempBuild = beam
Many thanks!