World Wrapping


One of the aspects of the game we determined we wanted early on was the feeling that you are on a planet. To give the player this feeling we decided that the player should never reach "the edge" of the map. But how to accomplish this in Unity? The idea we  came up with was to create a kind of tile system that would move the world around depending on the position of the player. 


In the diagram above, the "player" (represented by the hexagon) can run from right to left. When the player crosses a threshold, the part of the map in the opposite direction moves to the direction the player is moving. In order to prevent the player from just moving back and forth across a threshold and causing the map to constantly shift, the thresholds will be on either side of a tile, as seen in the bottom tile. In the case of the bottom tile, once the player passes through a threshold, the map will not shift again until the player passes through the opposite threshold of the same tile, or the same threshold of a different tile.

This is easily extended to the vertical direction by using a 2x2 array to keep track of the map. When the player moves left/right or up/down the array is shifted in the appropriate direction.

In the example above, the player starts in the middle of tile 0. When the player moves to the left, the right tiles must shift to keep the player "on planet". Then when  the player moves up, the bottom tiles must shift. This way no matter what direction the player is moving in, the correct tiles will always be moved in front of the player.

To accomplish this within Unity, each level will have 4 roots where each root is one the map tiles. All objects in the scene will be children of these roots, depending on where on the map they are located. This means that when a tile is moved, all objects on it will also be moved, removing the need to track static objects individually. For non-static objects, such as the alien NPC's, they will track which tile they are currently on and move themselves in the hierarchy accordingly when they switch to a new tile.

Using this system, we believe that it will give the player the feeling of being on a miniature planet and by moving around, they are running "around the world".

- Matt

Get Space Shepherd

Leave a comment

Log in with itch.io to leave a comment.