#Need Help on calculating Size and arrangement for an egg system

1 messages · Page 1 of 1 (latest)

rocky beacon
#

im trying to position eggs Infront of a camera so they all fit and scale to fit the screen size and arrange themselves like in pet sim 99

heres what i have so far


    
    local camera = workspace.CurrentCamera
    local Eggs = SpawnEggs()
    local eggMinOffset = 0.3
    
    
    local function  UpdateEggPositions(EGGS)
        local height = math.tan(math.rad(camera.FieldOfView/2)) * 2 * (eggMinOffset)
        local width = height * camera.ViewportSize.X / camera.ViewportSize.Y
        
        
        local rows = math.round(math.ceil(math.log(#Eggs)))
        local RowEggsAmount = math.round(#Eggs / rows)
        for i = 1,rows do
            for i = 1,RowEggsAmount do
                local Egg = EggModel:Clone()
                Egg:ScaleTo(0.05)
                
                
            end
        end
        
        --Old
        for i,v in Eggs do
            v:ScaleTo(0.05)
            local spacing = width / #Eggs
            
            local offsetindex = i - (#Eggs + 1) / 2
            local offsetPosX = offsetindex * (spacing)
            
            
            local Forward = camera.CFrame.LookVector
            local right = camera.CFrame.RightVector
            
            local TargetPos = camera.CFrame.Position
            + Forward * (v.PrimaryPart.Size.Z + eggMinOffset)
            + right * offsetPosX
            
            local FinalCFrame = CFrame.new(TargetPos,TargetPos + camera.CFrame.LookVector)
            v:SetPrimaryPartCFrame(FinalCFrame)
        end
    end
    
#

Need Help on calculating Size and arrangement for an egg system

ebon charm
#

dont they use gui for this systeM?

rocky beacon
#

they use 3d Models

ebon charm
#

i'd rather check the monitor height and width. and determine how much it would scale per pixel

rocky beacon
#

yea i got the height and width

#

inside the function

ebon charm
#

you make it hard

#

you can just use

#

mouse.viewsizeY

#

mouse.viewsizeX

rocky beacon
#

is that in studs

ebon charm
#

in screen pixel

#

and then

#

u will want to check

#

how much it'll scale

#

per pixel

#

then

#

it doesnt based on the camera anymore

#

it based on your screensize

#

but

#

i think

#

this wont work on mobile

#

since mobile doesnt has mouse

rocky beacon
#

yea true

#

i would use gui grid layout but the quality would be limiting

winged lichen
#

Use iframe

rocky beacon
winged lichen
#

try something like

#
local vpf = Instance.new("ViewportFrame", cloneContent)
vpf.Size = UDim2.fromScale(1, 1)
vpf.BackgroundTransparency = 1
vpf.AnchorPoint = Vector2.new(0.5, 0.5)
vpf.Position = UDim2.fromScale(0.5, 0.5)

local vpfcam = Instance.new("Camera", vpf)
vpf.CurrentCamera = vpfcam
vpfcam.FieldOfView = 30

local vpfmodel = Instance.new("Model", vpf)

local k, v = next(catalog.Accessories)
local numAccessories = 0 
for _ in catalog.Accessories do 
    numAccessories += 1 
end

for i = 1, math.random(0, numAccessories-2), 1 do 
    k, v = next(catalog.Accessories, k) 
end

local accessory = v:Clone()
accessory.Parent = vpfmodel

local rootpart = accessory:FindFirstChildWhichIsA("BasePart")
assert(rootpart, string.format("Could not find rootpart on accessory: %s", tostring(k)))
rootpart = rootpart.AssemblyRootPart or rootpart
vpfmodel.PrimaryPart = rootpart

vpfmodel:PivotTo(CFrame.new(Vector3.zero))

local orientation, size = vpfmodel:GetBoundingBox()
local maxSize = math.max(size.X, size.Y, size.Z)
local distance = maxSize * 1.5
vpfcam.CFrame = CFrame.lookAt(Vector3.new(0, size.Y/4, distance), Vector3.new(0, 0, 0), Vector3.yAxis)

vpf.Parent = cloneContent
rocky beacon
winged lichen
#

just format it

rocky beacon
winged lichen
#

could try something like

#
local EggDisplay = {}

function EggDisplay.createEggViewport(eggs, parentFrame)
    local vpf = Instance.new("ViewportFrame", parentFrame)
    vpf.Size = UDim2.fromScale(1, 1)
    vpf.BackgroundTransparency = 1
    vpf.AnchorPoint = Vector2.new(0.5, 0.5)
    vpf.Position = UDim2.fromScale(0.5, 0.5)

    local vpfcam = Instance.new("Camera", vpf)
    vpf.CurrentCamera = vpfcam
    vpfcam.FieldOfView = 30

    local vpfmodel = Instance.new("Model", vpf)

    local eggMinOffset = 0.3
    local camera = workspace.CurrentCamera

    local height = math.tan(math.rad(vpfcam.FieldOfView/2)) * 2 * (eggMinOffset)
    local width = height * vpf.ViewportSize.X / vpf.ViewportSize.Y
    local numEggs = #eggs
    local rows = math.max(1, math.round(math.ceil(math.log(numEggs))))
    local eggRowCount = math.max(1, math.round(numEggs / rows))

    for i, egg in ipairs(eggs) do
        local eggClone = egg:Clone()
        eggClone.Parent = vpfmodel

        if eggClone:FindFirstChildWhichIsA("BasePart") then
            local rootPart = eggClone:FindFirstChildWhichIsA("BasePart")
            local originalSize = rootPart.Size
            local scaleFactor = 0.05 / math.max(originalSize.X, originalSize.Y, originalSize.Z)
            
            for _, part in ipairs(eggClone:GetDescendants()) do
                if part:IsA("BasePart") then
                    part.Size = part.Size * scaleFactor
                end
            end
        end

        local rowIndex = math.floor((i-1) / eggRowCount) + 1
        local columnIndex = (i-1) % eggRowCount

        local spacing = width / eggRowCount
        local offsetX = (columnIndex - (eggRowCount-1)/2) * spacing
        local offsetY = (rowIndex - (rows-1)/2) * spacing

        local basePart = eggClone:FindFirstChildWhichIsA("BasePart")
        if basePart then
            local targetPos = Vector3.new(offsetX, offsetY, eggMinOffset)
            eggClone:PivotTo(CFrame.new(targetPos))
        end
    end

    local _, size = vpfmodel:GetBoundingBox()
    local maxSize = math.max(size.X, size.Y, size.Z)
    local distance = maxSize * 1.5
    vpfcam.CFrame = CFrame.lookAt(
        Vector3.new(0, size.Y/4, distance), 
        Vector3.new(0, 0, 0), 
        Vector3.yAxis
    )

    return vpf
end

return EggDisplay