Making an egg hatching animation

How would i go about making an animation with an egg infront of the players camera like bubble gum simulator

I know that i need to use renderstepped to position it infront and that works perfectly, its just i dont know how i would actually make it drop down and shake. Ive tried to tween it but that didnt work

Bubble gum simulator:
https://www.roblox.com/games/2512643572/SUPER-LUCK-EVENT-Bubble-Gum-Simulator?refPageId=f29ae929-213e-4888-b07f-36eb9cd55042

1 Like

Its made with ViewPortFrames and Eggs are in View Port Frames they are tweening to center and making tween rotation

1 Like

yeah thats what i thought at first before i saw this thread where one of the developers confirmed it was made by actual part infront of the camera, and viewport frames wouldnt allow effects and stuff like that

Are you using workspace.CurrentCamera:GetRenderCFrame()?

1 Like

no, could you explain how i could use that to help

1 Like

That function will get the exact position of the users camera.

If you use some additional CFrames, you should be able to do something like:

game:GetService('RunService').RenderStepped:Connect(function()
    egg.CFrame = workspace.CurrentCamera:GetRenderCFrame() * CFrame.new(2,0,-3.5) 
end)

It’ll position the egg (if you set the variable of egg to a mesh / part for the egg) infront of the camera, to the right.

We can use TweenService to make it move up and down with additional CFrames.
From what I know this second, your only option is to use a CFrameValue and multiply that by the Camera’s CFrame to get where you’d like to place it.

So, if we use something like that, your code should look something like:

local creature = workspace.Creature
local egg = workspace.Egg

local TS = game:GetService('TweenService')
local NCF = Instance.new('CFrameValue')
NCF.Value = CFrame.new(2,10,-3.5) -- Make the egg higher than the camera can see

function hatchEgg()
	local tween = TS:Create(NCF, TweenInfo.new(1.5), {CFrame = CFrame.new(2,0,-3.5)}) -- Make a tween which would make the egg drop down
	tween:Play()
	tween.Completed:Connect(function() -- Let it complete before "hatching" the egg
		local hatchTween = TS:Create(egg, TweenInfo.new(0.5), {Size = Vector3.new(0,0,0)})
		local hatchTween2 = TS:Create(creature, TweenInfo.new(0.5), {Size = Vector3.new(1,1,1)}) Change the 1,1,1 to the Size of the creature to come out
		hatchTween:Play()
		hatchTween2:Play()
		hatchTween.Completed:Connect(function()
			NCF.Value = CFrame.new(2,10,-3.5) -- Make the egg higher than the camera can see, again.
			egg.Size = Vector3.new(1,1,1) -- Change the 1,1,1 to the Size of the egg, so it'll revert meaning it can be used more than once
		end)
	end)
end

game:GetService('RunService').RenderStepped:Connect(function()
    egg.CFrame = workspace.CurrentCamera:GetRenderCFrame() * NCF.Value
end)

[2023 EDIT]
This code is incredibly unoptimized and if possible you should ensure that your tweens (and generally common-used objects) are cached to prevent a memory leak.

15 Likes

where do you call the hatch egg function? (i am very late lol)

1 Like

nevermind, i figured it out my self :slight_smile:

2 Likes

Where do you put the function?

1 Like