Skip to content

A 3D level: ground, a ramp, a moving platform, gems and a goal

Needs a game with "display": { "mode": "3d" }. The level goes in game/levels3d/, and a scene points at it with "level3d". Blocks are pieces, with position at the centre and sizes in metres (y is up). Everything else is a prefab placed as an object:

{
"schemaVersion": "0.1",
"id": "meadow",
"killY": -4,
"sky": { "color": "#8fd0ff", "fog": { "color": "#bfe6ff", "near": 30, "far": 90 } },
"pieces": [
{ "id": "ground", "shape": "box", "position": { "x": 0, "y": -0.5, "z": 0 }, "size": { "x": 24, "y": 1, "z": 24 }, "color": "#6cbf5a" },
{ "id": "ledge", "shape": "box", "position": { "x": 8, "y": 1, "z": 0 }, "size": { "x": 6, "y": 2, "z": 6 }, "color": "#8a9a5b" },
{ "id": "ramp", "shape": "ramp", "position": { "x": 3, "y": 1, "z": 0 }, "size": { "x": 4, "y": 2, "z": 3 }, "color": "#a6b36a" }
],
"objects": [
{ "kind": "spawn", "id": "player", "prefab": "runner", "position": { "x": 0, "y": 1, "z": -6 } },
{ "kind": "spawn", "prefab": "gem", "position": { "x": 8, "y": 2.9, "z": 0 } },
{ "kind": "spawn", "prefab": "lift", "position": { "x": -5, "y": 0.25, "z": 4 } },
{ "kind": "trigger", "position": { "x": 0, "y": 1, "z": 10 }, "size": { "x": 3, "y": 2, "z": 3 }, "event": "goal", "filterTag": "player" }
]
}

The moving platform (lift): a kinematic block that rises 3.6 m and back every 6 seconds. Characters on it ride along.

{
"schemaVersion": "0.1",
"id": "lift",
"components": {
"Transform3D": {},
"Mesh": { "shape": "box", "w": 2.5, "h": 0.5, "d": 2.5, "color": "#c9a46b" },
"Collider3D": { "w": 2.5, "h": 0.5, "d": 2.5 },
"Mover3D": { "y": 3.6, "period": 6 }
}
}

A gem that spins and is collected when touched (pickup:gem):

{
"schemaVersion": "0.1",
"id": "gem",
"components": {
"Transform3D": {},
"Mesh": { "shape": "sphere", "w": 0.5, "color": "#4fd1ff" },
"Collider3D": { "shape": "sphere", "w": 1, "sensor": true },
"Pickup": { "kind": "gem" },
"Spin3D": { "speed": 120 }
}
}

Rules: count gems, bring the player back after a fall, and finish at the goal:

[
{ "on": "pickup:gem", "do": [{ "action": "addToCounter", "counter": "gems", "amount": 1 }] },
{ "on": "player:fell", "do": [{ "action": "respawn", "entity": "player", "delayMs": 600 }] },
{ "on": "trigger:goal", "do": [{ "action": "goToScene", "scene": "win" }] }
]