So when using sine and cosine, and switching between how powerful they are, there can be some jagged movement. The reason I am asking is because I am making a game where player input can change the power of the sine and cosine. I made a sample script to show what I mean and people can test (if you want to know what I mean):
local Part = script.Parent
local RS = game:GetService("RunService")
local sine
do
local frequency
local phase = 0
sine = function(amplitude, newFrequency)
local t = tick()
if not frequency then
frequency = newFrequency
elseif math.abs(newFrequency - frequency) < 0.01 then
local oldArgument = t*frequency + phase
frequency = newFrequency
phase = oldArgument - t*frequency
end
print("Sine : " .. (amplitude * math.sin(t*frequency + phase)))
return amplitude * math.sin(t*frequency + phase)
end
end
local frames = 0
math.randomseed(tick())
local targetframes = math.random(300, 900)
local cf = true
RS.Stepped:Connect(function()
frames = frames + 1
if frames == targetframes then
frames = 0
targetframes = math.random(300, 900)
cf = not(cf)
end
if cf then
Part.CFrame = CFrame.new(-2, 2.5, 10) * CFrame.new(0, (sine(0.3, 1.2)), 0)
else
Part.CFrame = CFrame.new(-2, 2.5, 10) * CFrame.new(0, (sine(0.5, 16)), 0)
end
end)
However when the sine and cosine powers change, there can be some jagged movement, If anyone knows how to make the changes more smooth, it would be greatly appreciated! :)

1 comment
more smooth = more steps, less change