I am trying to make a connect city game by connecting 2 button GUI’s together with a road but it is not pointing exactly where the mouse is which will feel off. Only like 45 degrees from the top or bottom will point exactly where the mouse is but the size wont be exactly where the mouse is pointing at either. I have tried fixing this for a long time and never found out how to.
LocalScript:
btn.MouseButton1Down:Connect(function()
if not canDragRoads or btn.Parent.Parent.Roads:FindFirstChild("DRAGGING") then return end
currentDraggingCity = btn.Name
local roadClone = road:Clone()
roadClone.Parent = btn.Parent.Parent.Roads
roadClone.Name = "DRAGGING"
roadClone.AnchorPoint = Vector2.new(0.5, 0.5)
task.spawn(function()
while true do
if not roadClone or roadClone.Name ~= "DRAGGING" then break end
local mousePos = UserInputService:GetMouseLocation()
local stateImage = btn.Parent.Parent
local guiPos = stateImage.AbsolutePosition
local cityPos = btn.CityName.AbsolutePosition
local relX = cityPos.X - guiPos.X
local relY = cityPos.Y - guiPos.Y
local dir = (Vector2.new(mousePos.X, mousePos.Y) - Vector2.new(cityPos.X, cityPos.Y)).Unit
local dist = (Vector2.new(mousePos.X, mousePos.Y) - Vector2.new(cityPos.X, cityPos.Y)).Magnitude
local offset = dir * (dist / 2)
roadClone.AnchorPoint = Vector2.new(0.5, 0.5)
roadClone.Position = UDim2.new(0.04, relX + offset.X, -0.04, relY + offset.Y)
roadClone.Size = UDim2.new(0.058, 0, 0, dist)
roadClone.Rotation = math.deg(math.atan2(mousePos.Y - cityPos.Y, mousePos.X - cityPos.X)) + 90
task.wait()
end
end)
end)
Here is a video of what is happening: