So I made this drawing game that adds a small GUI on the mouse position every RenderStep, But the problem is if the fps is below a million, It will add some random GUI objects everywhere, And it sucks, So I made this script to fill the gaps between 2 Vector2 values, But it doesn’t work and I can’t locate the issue
Script ( very very very shortened )
local Start = Vector2.new(0, 100)
local End = Vector2.new(50, 200)
local v = (Start - End).Magnitude
for i=1, v do
local Position = Vector2.new(
Start.X / ((End.X / i) / v) / End.X,
Start.Y / ((End.Y / i) / v) / End.Y
)
print(Position)
end
local Start = Vector2.new(0, 100)
local End = Vector2.new(50, 200)
local v = (Start - End).Magnitude
for i=1, v do
local Position = Vector2.new(
Start.X / ((End.X / i) / v) / End.X,
Start.Y / ((End.Y / i) / v) / End.Y
)
print(Position)
end
ok ur code is very confusing so I rewrote it using lerps in a way that I assume would be more efficient (which is probably not)
function lerp(start, goal, alpha) --funee function i pasted from internet
return start + (goal - start) * alpha
end
--get position values and stuff
local startp = vector2.new(stuff)
local endp = vector2.new(stuff)
local deltap = (startp-endp).magnitude
--get how many dot thingies u will need to fill the gap
local offsetCorrectionMagnitude = deltap/squarethingy.X
local lerpMagnitude = 1/offsetCorrectionMagnitude
for c = 1, offsetCorrectionMagnitude, 1 do --place dots according to alpha
local dot = squarethingy:clone()
lerp(dot.X,endp.X,lerpMagnitude*c)
lerp(dot.Y,endp.Y,lerpMagnitude*c)
end
ok basically what I did get the required amount of dots to fill the gap and then spaced them through the gap using lerp. Very funny code, yes. Forgive it’s funniness.
Edit: Also I believe you can modify the resolutions of the gap-filled line by decreasing the increment in the for loop (I also believe this makes the thing more laggy)
squarethingy is the black square stuff on the picture you replied to me. Which is the paint part(i think). Also if scale doesn’t work use offset, if it still doesn’t work get its absolute size, and if it still doesn’t work idk man
deltatime argument should work here!
if you store the previous mouse position and current mouse position and use the deltatime as a gauge to how many squares you should add in the middle that should do the trick
you could use lerps but edit the amount of squares using these three variables as a factor, should be able to get good enough results with ((previous - current).magnitude)/deltaTime
what I would do is save that as a variable, and since its a decimal I would check if its above 1, round it, and then make a loop to have the appropriate amount of squares and spacing
op literally said he used Renderstep; and he literally said he wants to fill the space between them. You are just repeating what he wants to achieve lol
local Mouse = game:GetService("Players").LocalPlayer:GetMouse()
local LastMousePosition = Vector2.new(Mouse.X, Mouse.Y)
local function CreatePaint(X, Y)
print(X, Y)
end
game:GetService("RunService").RenderStepped:Connect(function(DeltaTime)
local LastMouseDistance = (LastMousePosition - Vector2.new(Mouse.X, Mouse.Y)).Magnitude
if LastMouseDistance > 2 then
local Start = Vector2.new(LastMousePosition.X, LastMousePosition.Y)
local End = Vector2.new(Mouse.X, Mouse.Y)
local v = (Start - End).Magnitude
for i=1, v do
local Position = Vector2.new(
Start.X / ((End.X / i) / v) / End.X,
Start.Y / ((End.Y / i) / v) / End.Y
)
CreatePaint(Position.X, Position.Y)
end
else
CreatePaint(Mouse.X, Mouse.Y)
end
LastMousePosition = Vector2.new(Mouse.X, Mouse.Y)
end)
I was trying to make how they calculated TweenService on Vector2 values Because when I use tween service, It will still have gaps unless I make the time on TweenInfo higher
But when I make it higher, You need to slowly wait for the tween to end
I changed it a bit because I didn’t read the documentary thingy
local Start = Vector2.new(0, 100)
local End = Vector2.new(50, 200)
local X1, X2 = math.round(Start.X), math.round(End.X)
local Y1, Y2 = math.round(Start.Y), math.round(End.Y)
local sx, sy, dx, dy
if X1 < X2 then sx = 1 dx = X2 - X1 else sx = -1 dx = X1 - X2 end
if Y1 < Y2 then sy = 1 dy = Y2 - Y1 else sy = -1 dy = Y1 - Y2 end
local err, e2 = dx-dy, nil
while not (X1 == X2 and Y1 == Y2) do
e2 = err + err
if e2 > -dy then err = err - dy X1 = X1 + sx end
if e2 < dx then err = err + dx Y1 = Y1 + sy end
local Position = Vector2.new(X1, Y1)
print(Position)
end
im not sure what equation you’re using in the loop, but I tinkered around with it and I didn’t seem to work for me, you should try using a normal lerp in my opinion, tried it out with that and it seemed to work
and the square amount doesn’t seem to be adapting either, weird… we could do some more experimentation with that!
(oops didn’t see previous post sorry, but still a cool topic to explore)
it would be way less laggy by actually using CanvasDraw’s pixel-based canvas and it’s draw pixel/line functions. You can get resolutions as high as 256x256 without any lag at all. But if you want higher resolutions, you can edit the module code to increase the resolution limit if you want