Hello, I have been working on an egg hatching system and I am rotating my egg using a smooth sine wave:
And I am trying to make it look like this:
Here is my function for displaying and rotating the egg:
function module:DisplayEgg(eggName)
local cframe = CFrame.new()
local egg = workspace['Eggs'][eggName]:Clone()
egg.Parent = camera
for _, part in pairs(egg:GetDescendants()) do
if part:IsA('BasePart') then
part.CanCollide = false
end
end
local offset = CFrame.new(0,0,-(egg.PrimaryPart.Size.Z * 1.5))
cframe = offset
local x = 8
local function onRenderStep(dt)
local angle = 50*math.sin(x*tick())
local eggCFrame = camera.CFrame * offset * CFrame.Angles(0, 0, math.rad(angle))
egg:SetPrimaryPartCFrame(eggCFrame)
end
connection1 = runService.RenderStepped:Connect(onRenderStep)
end
How can I make a sine wave get faster and faster?
Thank you!
function module:DisplayEgg(eggName)
local cframe = CFrame.new()
local egg = workspace['Eggs'][eggName]:Clone()
egg.Parent = camera
for _, part in pairs(egg:GetDescendants()) do
if part:IsA('BasePart') then
part.CanCollide = false
end
end
local offset = CFrame.new(0,0,-(egg.PrimaryPart.Size.Z * 1.5))
cframe = offset
local x = 1
local FrameCounter = 0
local function onRenderStep(dt)
local angle = 20*math.sin(x*tick())
local eggCFrame = camera.CFrame * offset * CFrame.Angles(0, 0, math.rad(angle))
egg:SetPrimaryPartCFrame(eggCFrame)
if FrameCounter == 10 then
FrameCounter = 0
x+=1
else
FrameCounter += 1
end
end
connection1 = runService.RenderStepped:Connect(onRenderStep)
end
function module:DisplayEgg(eggName)
local cframe = CFrame.new()
local egg = workspace['Eggs'][eggName]:Clone()
egg.Parent = camera
for _, part in pairs(egg:GetDescendants()) do
if part:IsA('BasePart') then
part.CanCollide = false
end
end
local offset = CFrame.new(0,0,-(egg.PrimaryPart.Size.Z * 1.5))
cframe = offset
local x = 1
local FrameCounter = 0
local function onRenderStep(dt)
if FrameCounter == 10 then
local angle = 20*math.sin(x*tick())
local eggCFrame = camera.CFrame * offset * CFrame.Angles(0, 0, math.rad(angle))
egg:SetPrimaryPartCFrame(eggCFrame)
FrameCounter = 0
x+=1
else
FrameCounter += 1
end
end
connection1 = runService.RenderStepped:Connect(onRenderStep)
end
function module:DisplayEgg(eggName)
local cframe = CFrame.new()
local egg = workspace['Eggs'][eggName]:Clone()
egg.Parent = camera
for _, part in pairs(egg:GetDescendants()) do
if part:IsA('BasePart') then
part.CanCollide = false
end
end
local offset = CFrame.new(0,0,-(egg.PrimaryPart.Size.Z * 1.5))
cframe = offset
local x = 8
local startTick = tick()
local function onRenderStep(dt)
local currentTick = tick()
local speed = currentTick - startTick + 1
local angle = 50*math.sin(speed * x * currentTick)
local eggCFrame = camera.CFrame * offset * CFrame.Angles(0, 0, math.rad(angle))
egg:SetPrimaryPartCFrame(eggCFrame)
end
connection1 = runService.RenderStepped:Connect(onRenderStep)
end
The idea is that you multiply x by a given speed. In this case, the speed is defined as the interval between the start and the current time. That means that the speed increases over time.
Thank you! But how do I implement it? I tried this:
function module:DisplayEgg(eggName)
local cframe = CFrame.new()
local egg = workspace['Eggs'][eggName]:Clone()
egg.Parent = camera
for _, part in pairs(egg:GetDescendants()) do
if part:IsA('BasePart') then
part.CanCollide = false
end
end
local offset = CFrame.new(0,0,-(egg.PrimaryPart.Size.Z * 1.5))
cframe = offset
local x = 8
local startTick = tick()
local function onRenderStep(dt)
local currentTick = tick()
local speedScale = 1 / 10
local maxSpeed = 5
local interval = (currentTick - startTick + 1)
-- Clamp the speed
local speed = math.min(interval * speedScale, maxSpeed)
local angle = 50 * math.sin(interval * speed * x * currentTick)
local eggCFrame = camera.CFrame * offset * CFrame.Angles(0, 0, math.rad(angle))
egg:SetPrimaryPartCFrame(eggCFrame)
end
connection1 = runService.RenderStepped:Connect(onRenderStep)
end
function module:DisplayEgg(eggName)
local cframe = CFrame.new()
local egg = workspace['Eggs'][eggName]:Clone()
egg.Parent = camera
for _, part in pairs(egg:GetDescendants()) do
if part:IsA('BasePart') then
part.CanCollide = false
end
end
local offset = CFrame.new(0,0,-(egg.PrimaryPart.Size.Z * 1.5))
cframe = offset
local x = 8
local startTick = tick()
local speedScale = 1 / 10
local maxSpeed = 5
local function onRenderStep(dt)
local interval = tick() - startTick
-- Clamp the speed
local speed = math.min(interval * speedScale, maxSpeed)
local angle = 50 * math.sin(speed * x)
local eggCFrame = camera.CFrame * offset * CFrame.Angles(0, 0, math.rad(angle))
egg:SetPrimaryPartCFrame(eggCFrame)
end
connection1 = runService.RenderStepped:Connect(onRenderStep)
end
function module:DisplayEgg(eggName)
local cframe = CFrame.new()
local egg = workspace['Eggs'][eggName]:Clone()
egg.Parent = camera
for _, part in pairs(egg:GetDescendants()) do
if part:IsA('BasePart') then
part.CanCollide = false
end
end
local offset = CFrame.new(0,0,-(egg.PrimaryPart.Size.Z * 1.5))
cframe = offset
local x = 8
local t = 0
local decay = 10
local startSpeed = 5
local function onRenderStep(dt)
-- Start at 1 and move to 0 over time
local speed = math.max(-speed / decay * t + startSpeed , 0)
local angle = 50 * math.sin(t * speed * x)
local eggCFrame = camera.CFrame * offset * CFrame.Angles(0, 0, math.rad(angle))
egg:SetPrimaryPartCFrame(eggCFrame)
-- Keep track of time
t = t + dt
end
connection1 = runService.RenderStepped:Connect(onRenderStep)
end