I want to create a fluid Spray Paint System Like the one in the famous game Spray Paint! However, I don’t seem to be getting the Fluidity right as I keep getting gaps when I move the mouse at a moderate speed. I have scanned the Developer Forum and I still haven’t found a Solution So Far. I’m terrible at math so some code would be appreciated along with some Insight.
What is the issue?
There are Gaps whenever the mouse moves at moderate speed even when render stepped is used.
Here is the Code that ive been using!
local tool = script.Parent
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ToolClient = require(script.ToolClient)
tool.Equipped:Connect(function(mouse)
local player = game.Players:GetPlayerFromCharacter(tool.Parent)
local isMouseDown = false
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isMouseDown = true
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isMouseDown = false
end
end)
game["Run Service"].RenderStepped:Connect(function()
if isMouseDown then
local sprayCFrame = ToolClient:CalculateSpray(player)
local part = script.Octagon:Clone()
part.Anchored = true
part.CanCollide = false
part.Color = Color3.new(0, 1, 1)
part.CFrame = sprayCFrame
part.Parent = game.Workspace.Art
end
end)
end)
Here is what’s inside the ToolClient if that Helps.
local module = {}
function module:CalculateSpray(player: Player)
local mouse = player:GetMouse()
local ray = Ray.new(
mouse.UnitRay.Origin,
mouse.UnitRay.Direction * 1000
)
local part, position, normal = workspace:FindPartOnRayWithIgnoreList(ray,{player.Character,workspace.Art})
local sprayCFrame = CFrame.new(position, position + normal)
local lookOBJSpace = sprayCFrame:PointToObjectSpace(player.Character:FindFirstChild("HumanoidRootPart").Position)
local FaceRadians = math.atan2(lookOBJSpace.Y, lookOBJSpace.X)
local REALSprayCFrame = sprayCFrame * CFrame.Angles(math.rad(-180), math.rad(90), 0)
if part then
return REALSprayCFrame
end
end
return module
I would create 2 circular GUI Objects, and one line. The line will reach from the last Mouse position to the current position, and the circles will be placed on both ends. (What the person above me said. 10 seconds earlier.)
I’m don’t have time, but here is another explanation. Every heartbeat or renderstepped, you save the mouse position. The next heartbeat or renderstepped, you create a line from the last mouse position, to the current position. (So you should have a blocky path whereever your mouse goes.) Finally, you will put 2 circles smack dab at the current position, and the last posiiton, to give the effect of many small circles. Make sense?