Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function createLine(startPos, endPos)
- local line = Instance.new("Frame")
- -- line.Size = UDim2.new(0, (endPos - startPos).Magnitude, 0, 2)
- line.Size = UDim2.new(0, 5, 0, 2)
- line.Position = UDim2.new(0, startPos.X, 0, startPos.Y)
- line.AnchorPoint = Vector2.new(0, 0.5)
- line.Rotation = math.deg(math.atan2(endPos.Y - startPos.Y, endPos.X - startPos.X))
- line.BackgroundColor3 = Color3.new(1, 0, 0)
- line.BorderSizePixel = 0
- line.Parent = Canvas
- end
- local function getRelativePosition(input)
- local absolutePosition = Canvas.AbsolutePosition
- local relativePosition = Vector2.new(input.Position.X - absolutePosition.X, input.Position.Y - absolutePosition.Y)
- return relativePosition
- end
- UserInputService.InputBegan:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
- drawing = true
- lastPosition = getRelativePosition(input)
- end
- end)
- UserInputService.InputEnded:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
- drawing = false
- lastPosition = nil
- end
- end)
- UserInputService.InputChanged:Connect(function(input)
- if drawing and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then
- local currentPosition = getRelativePosition(input)
- if lastPosition then
- createLine(lastPosition, currentPosition)
- end
- lastPosition = currentPosition
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement