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
- CData[4] : 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.CData[4]
if pfJ.Bg then
pfJ.Scale.z = pfI.Scale.z - pfJ.CData[4] / pfJ.sizeZ
end
end
end
end
end
end
- "char" script: pattern parameters used:
- CData[5] : the delta value help determine if a char is on top of a platform
function Start()
charList = {}
end
function End()
charList = nil
end
function Update()
for i = 1, #charList do
charList[i] = nil
end
charCount = 0
end
function UpdateS()
charCount = charCount + 1
charList[charCount] = shape
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.CData[5] <= y and s.BottomLeft.x + s.CData[6] <= x2 and s.TopRight.x - s.CData[6] >= x1 then
if pfNear == nil or yNear < s.TopRight.y + s.Offset.y then
pfNear = s
yNear = s.TopRight.y + s.Offset.y
end
end
end
if pfNear then
shape.Offset.z = shape.Offset.z + pfNear.Offset.z - pfNear.refPattern3D.CData[4] - shape.sizeZ/2
end
end