Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(1 edit)

Multi-depth platforming solution

There are games like SMB3 or Chip&Dale Rescue Ranger where it makes more sense to position platforms at different depths in 3d scene. How to calculate all the platform depths and moreover characters's depth who are sitting on top of those platforms? Obviously this is a dynamic problem that only could be solved after having the 2d output of each scene. The addopted solution of 3dSen is addopted in the video bellow with the help of two script tagged "pf" and "char"

- "pf" script:  pattern parameters used in this script

  • DeformSpeed.m00 : the z offset of the upper platform compared to its lower one
function Start()
    pfList = {}
end
function End()
    pfList = nil
end
function Update()
    for i = 1, #pfList do
        pfList[i] = nil
    end
    pfs = Frame:GetShapesWithTag("pf")
    for i = 0, pfs.Count - 1 do
        pfList[i + 1] = pfs[i]
        pfList[i + 1].Pivot.z = 0
    end
    if #pfList > 0 then
        UpdatePf()
    end
end
function Compare(s1, s2)
    if s1.TopRight.y < s2.TopRight.y then
        return true
    else 
        return false
    end
end
function max(a,b)
    if a > b then
        return a;
    else
        return b;
    end
end
function UpdatePf()
    --print(#pfList)
    table.sort(pfList, Compare)
    for i = 1, #pfList -1 do
        pfI = pfList[i]
        for j = i + 1, #pfList do
            pfJ = pfList[j]
            if pfI.TopRight.y + 16 > pfJ.BottomLeft.y and pfI.BottomLeft.x <= pfJ.TopRight.x and pfI.TopRight.x >= pfJ.BottomLeft.x then
                if pfJ.Offset.z  < pfI.Offset.z + 8 then
                    pfJ.Layer = pfI.Layer
                    pfJ.Offset.z = pfI.Offset.z + pfJ.DeformSpeed.m00
                    if pfJ.Bg then
                        pfJ.Scale.z = pfI.Scale.z - pfJ.DeformSpeed.m00 / pfJ.sizeZ 
                    end
                end
            end
        end 
    end
end

- "char" script: pattern parameters used:

  • DeformSpeed.m10 : the delta value help determine if a char in on top of a platform
function UpdateS()
    if #pfList == 0 then
        return
    end
    --print(#pfList)
    local pfNear = nil
    local yNear = 0
    local y = shape.BottomLeft.y
    local x1, x2 = shape.BottomLeft.x, shape.TopRight.x
    for i = 1, #pfList do
        s = pfList[i]
        if s.TopRight.y - s.DeformSpeed.m10 <= y and s.BottomLeft.x <= x2 and s.TopRight.x >= x1   then
            if pfNear == nil or yNear < s.TopRight.y then
                pfNear = s
                yNear = s.TopRight.y
            end
        end
    end
    if pfNear ~= nil then
        shape.Offset.z = shape.Offset.z + pfNear.Offset.z
    end
end