- Home /
How best should I "repeat" a 2D platform level with finite width to make it endless?
If I have a scene that's a simple 2D platform, wider than the camera view horizontally, are there any common/accepted best practices to make it "endless" - so that when you reach the furthest right hand side it repeats and you're back at the left? i.e if I knock this together:
And you pass the 6th raised platform, the 1st raised platform will be visible again. So essentially you're playing the same level but could be running endlessly. (I'm sure there's a proper name for this...).
The best results I've found so far are when I manually set the player's position.x coordinate so it essentially shoots back to the left when it hits a threshold on the right, but this means the whole screen has to be clear of things like platforms, enemies, etc so they don't disappear.
I'd also prefer not to make loads of duplicate objects or, if I have to, only temporary ones to help make the effect work - mainly because in my levels there are a finite number of objects that will change as the player continues to pass through and it matters that they only see the same objects on each pass through the level.
Hope that makes sense! Any help on reading or next steps to try would be much appreciated!
Answer by Shifty-Geezer · Jul 21, 2017 at 09:08 PM
Duplicate the end parts of the level at the beginning so that when you blip back to the left, it looks the same. If you don't want them visible, mask them (disable) on first start. Alternatively, reposition the objects to the right as the player runs and scroll infinitely. This is what I'm doing with my wrap-around space shooter - when an object gets too far away travelling in one direction, position it on the other side of screen to scroll into view.
Ultimately it depends on how you are creating your level. Infinite runners will be procedurally generated, so you can create blocks at start and hide/show/position as you go. Don't forget it's perfectly acceptable to just move objects off screen (and disable the GameObject)! So create platforms 1-20 at start, then position them at runtime off the right as the player gets near, and disappear them when they're off to the left.
Thanks - definitely some things to think about here. $$anonymous$$y levels will all be static - so the same objects in the exact same positions on every play of the game. Would you suggest a specific solution for that (i.e. reposition versus duplicate)?
Are they repeating? Does it go object 1 - 2 - 3 - 1 - 2 - 3 - 1 - 2 - 3 - 1 - 2 - 3 every play in an infinite loop, or procedurally generated 1 - 2 - 2 - 1 - 3 - 1 - 3 - 2 - 3 - 1 - 3 - 3 - 1 - 2 every play where the level keeps varying as you run? If the former, I'd say create your level and blip the player back to the beginning. That way you can see the level while designing. If the latter, keep the player running right and teleport each obstacle in of screen just ahead of the player as needed, then disable it when it disappears off the left.
Yeah the former. It will be exactly the same. It does seem like blipping the player back to the beginning would be the simplest - it's just making it appear smooth and not having to have a full "blank" screen to do so
Answer by Getsumi3 · Jul 23, 2017 at 01:48 PM
May be you'll be interested http://pixelnest.io/tutorials/2d-game-unity/table-of-contents/
Your answer
Follow this Question
Related Questions
How do go about making "Frogger" traffic? 0 Answers
2D Pixel Platformer Problems 1 Answer
Play and Stop Animation 1 Answer
Flip Player, but don't flip the Player's Child. 2 Answers
How do I attach a script to a state 1 Answer