I am trying to make an egg hatching system where players can open eggs for pets. In order to do this, I need to ensure the egg is facing the correct direction to the camera.
I want to carry over the same orientation of these eggs to when they get positioned in front of the camera. For example, when opening this egg:
It gets positioned facing the opposite direction during the hatching animation:
I have tried to use the orientation of the egg in the game in my code to make it face the correct way however that doesnt seem to work.
This is my code on how I position the egg:
I am using a CFrameAngles value to deal with the egg orientation, this is so when the user moves their camera it doesn’t rotate a different way.
local eggMesh = egg.PrimaryPart:Clone()
eggMesh.Anchored = true
eggMesh.CanCollide = false
eggMesh.Size = eggMesh.Size/5
local starsParticle = stars:Clone()
starsParticle.Parent = eggMesh
local CFrameValue = Instance.new("CFrameValue")
local CFrameAngles = Instance.new("CFrameValue")
CFrameAngles.Value = CFrame.Angles(0,0,0)
CFrameValue.Value = CFrame.new(0,-5,-eggMesh.Size.Z*4)
local eggConnection = runService.RenderStepped:Connect(function()
eggMesh.CFrame = camera:GetRenderCFrame() * CFrameValue.Value * CFrameAngles.Value
end)
eggMesh.Parent = camera
Any help would be greatly appreciated.