How would I make an egg decrease in it's distance from the camera?

So I have this script:

            local conc
            conc = RunService.RenderStepped:Connect(function()
                Egg:PivotTo(Camera.CFrame * CFrame.new(0,0,(-Egg.PrimaryPart.Size.Z * 2))*CFrame.Angles(0,0,math.sin((tick() - StartTime)*10)/1.5))
            end)

I was just wondering if there is a way for me to change the 2 using a function like sine, I did think of just using a for loop and updating a variable, but I don’t know if that’s the best way

1 Like
math.sin(deltaTime)

try this perhaps instead of the 2

This won’t work since DeltaTime is the time in between each frame, so it will give a different number for different clients, and will also be a very small number(1/FPS)

you didn’t even explain why you wanted to change the 2, what was the issue in the first place?

I am not completely sure what your problem is but if you want the distance to gradually increase this may work:

local conc
local step = 0.5

conc = RunService.RenderStepped:Connect(function()
	Egg:PivotTo(Camera.CFrame * CFrame.new(0,0,(-Egg.PrimaryPart.Size.Z * step))*CFrame.Angles(0,0,math.sin((tick() - StartTime)*10)/1.5))
	step += 0.1
end)

who the f names connection conc

I do, EQWEUQUQEFJQTGNQGOQIJGQEGJIQGOEGJQ_IGHQWJGU(EQGH – random stuff for extra characters :slight_smile:

I thought about this, but is this the but method?

I think that is about as optimized as it gets :grin:

Or you could use a tween:

local ts = game:GetService("TweenService")
local conc
local tweenInfo = TweenInfo.new(
	3, --tween time
	Enum.EasingStyle.Sine --easing
)
local goal = {}
goal.CFrame = Camera.CFrame * CFrame.new(0,0,(-Egg.PrimaryPart.Size.Z * 5))*CFrame.Angles(0,0,math.sin((tick() - StartTime)*10)/1.5)

local function TweenEgg()
	local tween = ts:Create(Egg,tweenInfo,goal)
	tween:Play()
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.