I am making a egg hatching animation where I use the camera and egg part to make the egg seem as if it is actually on screen as a GUI.
However, I somehow can’t wrap my head around how I would tween the position and orientation of this egg part while it’s CFrame is constantly being updated to that of the camera’s (to keep it on screen).
Would anyone know how I would go about this?
Here is the code for keeping the egg on screen:
local eggMesh = egg:FindFirstChild("EggMesh"):Clone()
for i, v in pairs(eggMesh:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = true
v.CanCollide = false
local hatchConnection = runService.RenderStepped:Connect(function()
local cf = CFrame.new(0,0,-eggMesh.PrimaryPart.Size.Z*2)
eggMesh:SetPrimaryPartCFrame(camera.CFrame * cf)
Oh, I thought you would have the tween be a very short one (one where you could run it many times for the changing camera). I mean I don’t think you can change the goal but you can make a short tween and make it’s goal based off of it’s position to wherever you want it to go. Do you have to have the camera be movable?
I mean that is a potential fix but I personally don’t want to go down this route. I know it is possible to somehow tween them while fixing them to the camera’s position constantly as I’ve seen it in games such as Pet Sim X and Sword Fighters Simulator.
Aren’t those done with GUI? (Never played them, sorry.) But another possible solution could be changing the animation. I don’t know how exactly the hatching would look like, but for example you can have the egg rotating and turning really quickly while still updating its position (you could also have it speed up the rotation aswell) until it hatches.
Well, previously I had a working hatching animation with using viewport frames however I have now had to switch to using cameras instead as I wanted to include particles.
I know those games use cameras too because the eggs/pets on screen interact with the game objects if you move your camera around.
I would probably go about it by:
Get start time.
Get the goal relative to the camera.
Create the tween and play.
Then in a loop continuously cancel the tween, getting and setting the new goal position and adjusting duration from start before creating a new tween to play.
Once the tween completes in one direction, use a second tween to move it back using the same principles. And so on to create a back and forth rocking motion.
(The reverses arg would need to be false, as this would not reset the position relative to the camera.)