I have been searching for a way to allow people to use fps unlocker my games.
function collectionVfx.tweenUi(icon, endPosition)
local pos = UDim2.fromScale(math.random(4, 8) / 10, math.random(1, 10) / 10)
local NewBezier = bezierService.new(1, icon.Position, pos, endPosition)
NewBezier:CreatePoints()
for i = 0, 1, .020 do
Icon.Position = NewBezier.Points[i]
RunService.RenderStepped:Wait()
end
NewBezier = nil
end
I’m not sure how I would incorporate delta to work with Bezier curves. When I use fps unlocker in my game it speeds the animation up. I want it to stay at a constant speed on any framerate
The error comes from within your for loop, because you wait for render step, this doesn’t scale with any frame rate. This should fix it:
local total = 0
local connection
connection = RunService.RenderStepped:Connect(function(step)
total = total + (0.02 * step * 60) -- Scale with step to match all frame rates
Icon.Position = NewBezier.Points[total]
if total > 1 then
connection:Disconnect()
return
end
end)
Hello, I implemented your fix and it somewhat works.
function collectionVfx.TweenUi(Icon, endPosition)
local Pos = UDim2.fromScale(math.random(4, 8) / 10, math.random(1, 10) / 10)
local total = 0
local connection
--
connection = RunService.RenderStepped:Connect(function(step)
print(total)
total += (0.02 * step * 60) -- Scale with step to match all frame rates
Icon.Position = bezierService.CreatePoint(total, {
["p0"] = Icon.Position,
["p1"] = Pos,
["p2"] = endPosition,
})
if total > 1 then
connection:Disconnect()
return
end
end)
end
It feels slower and more linear whereas before it sped up closer to the end.
It may have something to do with how I create my Bezier curves.
local Bezier = {}
Bezier.__index = Bezier
function Bezier.CreatePoint(t, Variables)
local a = Variables.p0:Lerp(Variables.p1, t)
local b = Variables.p1:Lerp(Variables.p2, t)
return a:Lerp(b, t)
end
function Bezier.new(Time, Start, Mid, End)
local New = {}
setmetatable(New, Bezier)
New.Variables = {
["t"] = Time,
["p0"] = Start,
["p1"] = Mid,
["p2"] = End,
}
return New
end
function Bezier:CreatePoints()
local Variables = self.Variables
self.Points = {}
for i = 0, Variables.t, 0.020 do
local Bez = Bezier.CreatePoint(i, Variables)
self.Points[i] = Bez
end
return self.Points
end
return Bezier
The problem comes from within the CreatePoints function. Bezier curve points aren’t always the same distance. Theres a complicated technique called “arc length parameterisation”. I can’t explain it right now on my phone but it basically involves having equally spaced distances instead of time increments.
One solution that I can think of would be to remove all points that are too close to each-other. I don’t know if your bezier is used in 2d or 3d so I can’t help on that.