Examples
Crosshair and FOV circle
A crosshair in the middle of the Roblox window, made of four lines and a dot, and a circle that follows your cursor. The crosshair re-centres itself when you resize the window.
Luau
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local COLOR = Color3.fromRGB(0, 255, 140)
local LENGTH, GAP, THICKNESS = 8, 4, 2
local CIRCLE_RADIUS = 120
local arms = {}
for i = 1, 4 do
local line = Drawing.new("Line")
line.Color = COLOR
line.Thickness = THICKNESS
line.ZIndex = 2
line.Visible = true
arms[i] = line
end
local dot = Drawing.new("Circle")
dot.Radius = 1.5
dot.Filled = true
dot.Color = COLOR
dot.ZIndex = 2
dot.Visible = true
local circle = Drawing.new("Circle")
circle.Radius = CIRCLE_RADIUS
circle.Thickness = 1
circle.Color = Color3.new(1, 1, 1)
circle.Transparency = 0.5
circle.Visible = true
local directions = {
Vector2.new(-1, 0),
Vector2.new(1, 0),
Vector2.new(0, -1),
Vector2.new(0, 1),
}
RunService.RenderStepped:Connect(function()
local center = workspace.CurrentCamera.ViewportSize / 2
for i, direction in ipairs(directions) do
arms[i].From = center + direction * GAP
arms[i].To = center + direction * (GAP + LENGTH)
end
dot.Position = center
circle.Position = UserInputService:GetMouseLocation()
end)Vectors add, subtract and scale like numbers, which keeps the arm maths short: center + direction * GAP is the point GAP pixels from the centre in that direction.
Things to change
- Put the circle in the centre too with
circle.Position = center. Most first person games lock the cursor there anyway. circle.NumSides = 6turns the circle into a hexagon.- Give the crosshair an outline by drawing the same four lines underneath in black with
Thickness = THICKNESS + 2andZIndex = 1.