2
\$\begingroup\$

In Unity, I'm trying to create a puzzle in a 2D platformer game where the player has to face some infinite stairs. The player can move left, right and jump.

The idea is that at some point the player encounters some stairs that they try to climb. They climb, and climb, and climb and soon realize there is no end to them. At whatever point they decide to go back down the stairs they realize there are only a couple of them till they found themselves where they started.

Does anyone have any rough idea how something like this can be done?

enter image description here

\$\endgroup\$
2

1 Answer 1

1
\$\begingroup\$
  1. Create two prefabs: "stairs" and "stairs with bottom and door". Both prefabs should be larger than a whole screen.
  2. Create a scene with one instance of the "stairs with bottom and door" prefab and a "stairs" prefab ahead.
  3. Whenever the player moves up, Instantiate a new stairs prefab ahead of them and Destroy the prefab below them.
  4. When the player moves down, Destroy the prefab ahead of them and Instantiate the "stairs with bottom and door" prefab below them.
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Note that if you never teleport the player character, it can be difficult to reconnect with other content in the level - everything would need to be a module spawned just in time this way. There's also the risk that the player could run so far up these infinite stairs that they get a long way from the origin where floating point precision starts to get thin, causing visible glitching. \$\endgroup\$
    – DMGregory
    Dec 26, 2021 at 14:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .