How to tween a Model in Camera

I am pretty sure everything they use for the Egg System is in CurrentCamera because all the Eggs go into the Camera, all the particles like confetti go into the camera, etcetera. (one way you can tell they do is because if you zoom in, it will actually go through the character)

Whenever I try and do this, I just get these errors.
image

do

pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(camera.CFrame * cf, game.ReplicatedStorage.NumberValue.Value)) -- Sets the position in Camera

If I do that this happens, it basically goes chaotic and flickers in a really weird way in an unknown position

try making the default value of the numbervalue 1 then see what happens

Whenever the value is set to 1, it does indeed go to the middle of the screen, but if it’s any other number, it breaks out. But I don’t see how this would make it tween downwards.

local goalCf = CFrame.new(pet.PrimaryPart.Position - Vector3.new(0, 10, 0)) -- destination of the pet (the end position of when it tweens down, should be someplace out of sight)
pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(goalCf, game.ReplicatedStorage.NumberValue.Value)) -- if the numbervalue = 0 then it will do nothing(keep at middle of screen) and when its 1 one it will be at the goal cframe (the cframe that is off the screen)

And then somewhere else you would do

game:GetService("TweenService"):Create(game.ReplicatedStorage.NumberValue, TweenInfo.new(1), {Value = 1}):Play() -- this will set the pet off the screen

and make sure when you want the pet to be on the screen, game.ReplicatedStorage.NumberValue.Value == 0 and when you want it to be off the screen game.ReplicatedStorage.NumberValue.Value == 1. Hope this helps clear things up.

Is the

local goalCf = CFrame.new(pet.PrimaryPart.Position - Vector3.new(0, 10, 0)) -- destination of the pet (the end position of when it tweens down, should be someplace out of sight) but also sometimes the pet is just somewhere random
pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(goalCf, game.ReplicatedStorage.NumberValue.Value)) -- if the numbervalue = 0 then it will do nothing(keep at middle of screen) and when its 1 one it will be at the goal cframe (the cframe that is off the screen)

Part supposed to be in the RunService place? Cause this happens (and yes at the end it does seem to tween but it doesn’t stay in the camera)

yes put that part in the Renderstepped function

So how can I fix the issue in the video? Sometimes the pet doesn’t even show up in plain sight (and yes, I changed it back to 0 when the egg hatches, yet it’s still underground after the first hatch)

	petOneConnection = runService.RenderStepped:Connect(function()
		local lookPart = pet.PrimaryPart -- Gets the lookPart for the LookAt part
		local cf = CFrame.new(0,0,-pet.PrimaryPart.Size.Z * 2) -- CFrame
		pet:SetPrimaryPartCFrame(camera.CFrame * cf) -- Sets the position in Camera
        local goalCf = CFrame.new(pet.PrimaryPart.Position - Vector3.new(0, 10, 0)) -- destination of the pet (the end position of when it tweens down, should be someplace out of sight)
        pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(goalCf, game.ReplicatedStorage.NumberValue.Value)) -- if the numbervalue = 0 then it will do nothing(keep at middle of screen) and when its 1 one it will be at the goal cframe (the cframe that is off the screen)
		lookPart.CFrame = CFrame.lookAt(lookPart.Position, camera.CFrame.Position) -- Sets the lookAt part to always look at your camera
	end)

    pet.Parent = camera

Try this

Same (sorta) issue.

That seems to work, what’s wrong with it? And make sure you set the numbervalue back to 0 once your done with the pet animation thing.

The thing is, the value is set to 0 once it rehatches.

As long as you set it back to 0 before a second animation plays then you should be good


No matter what, the value gets set back to 0?

Sorry but I see a solution to your problem but I don’t think it’ll work because I can’t see much here.

My suggestion was:

When you want to make the model tween out of site you

  • Disconnect from the renderstep
  • you either use :Lerp or TweenService:Create or whatever tween method and tween off screen
  • Set the parent of the model to nil or ReplicatedStorage or where ever

My sample code was if I pressed KeyPad1 then it would tween off screen

local runService = game:GetService("RunService")
local pet = workspace.Rando
local camera = workspace.CurrentCamera
local tweenservice = game:GetService("TweenService")
local blankinfo = TweenInfo.new(2,Enum.EasingStyle.Linear, Enum.EasingDirection.Out)


petOneConnection = runService.RenderStepped:Connect(function()
	local lookPart = pet.PrimaryPart -- Gets the lookPart for the LookAt part
	local cf = CFrame.new(0,0,-pet.PrimaryPart.Size.Z * 5) -- CFrame
	pet:SetPrimaryPartCFrame(camera.CFrame * cf) -- Sets the position in Camera
	lookPart.CFrame = CFrame.lookAt(lookPart.Position, camera.CFrame.Position) -- Sets the lookAt part to always look at your camera
end)

pet.Parent = camera

game:GetService("UserInputService").InputBegan:Connect(function(input, typing)
	if typing then return end
	
	if input.KeyCode == Enum.KeyCode.KeypadOne then
		
		local origin = pet:GetPivot()
		petOneConnection:Disconnect() -- disconnect from renderstep loop
		tweenservice:Create(pet.PrimaryPart, blankinfo, {CFrame = origin * CFrame.new(0,-50,0)}):Play() -- tween off screen
		task.wait(2.1) -- wait how long you want until
		pet.Parent = game.ReplicatedStorage -- set pet's parent
	end
	
end)

Note this is an example and should be used to edit your code and not use as a final solution.

Well yes this would work pretty much, but one of the issues that I am having is that if you were to zoom out or walk away, you would see the pet tween down not in camera.

That is true well then you either have two options:

1 Lock their camera to one position until it’s tween is finished
2 Use ViewPortFrame

Ps- ViewPortFrame is easier and locking the player screen to one position isn’t a good idea

Well, the thing about ViewportFrames is that for one, you don’t see the model(s) particles, etcetera. And I am not sure how I would do lookAt with Viewportframes.