This is a general question that could apply to both 2D and 3D
Rarely have I seen a game, maybe ever, that plays out in a world where you loop around when you reach the edge of a map
For example if you travel East in the mercator projection, eventually you’ll start seeing the western side of the map
I am not looking for just teleportation, the camera must accompany you throughout your journey across the bounds of the map and into the opposite bound, for a seemless transition
The rarity or inexistance of this mechanic in even AAA games makes me question if itss just a design decision to make a contained world map with bounds, or if there is just some kind of inpracticality with this idea?
Evidentely it seems that it would be much easier to accomplish in 2D, but I was thinking that maybe as you reach the edge you could instantiate a bit of extra map that mimics the opposite edge and try to slowly transition the player across
Has anyone ever thought about this topic or has any examples of games that would use this? The most that I can think of is super mario galaxy where the maps really were spherical so there was no need for this extra trickery
How would you implement this?
Any thoughts on the topic appreciated
One way is to have the player be static and the rest of the world move opposite to him.
Then the world objects only go out to a certain rectangle and wrap, hopefully out of sight.
If the visible world is the screen then there needs to be some dupe-object trickery, which is trivial if you just need to replicate a sprite (up to four times for each corner / side wrap), but gets hairier if you’re relying on Unity for collisions.
Another way is to have copies of the world that you stamp around beside the current one, but obviously you might need up to three copies of the world if the player approaches a corner.
Here was how I did it in one recent asteroids-y kinda game:
namespace Blaster
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// This is the one for non-Rigidbody2D things, like Asteroids
// There may also need to be another wrapper for bullets, which cast a streak
public class BlasterEdgeWrapper : MonoBehaviour
{
// I'm choosing not to simply wrap the max minus min so that screen
// dimensional changes don't make rocks appear mid-screen.
float inset = 0.01f;
// FixedUpdate because we are a hand-moved object
// in an otherwise-physics world.
void FixedUpdate()
{
// world positions
Vector2 LL = BlasterMetrics.Instance.LowerLeft;
Vector2 UR = BlasterMetrics.Instance.UpperRight;
Vector3 position = transform.position;
if (position.x > UR.x)
{
position.x = LL.x + inset;
}
if (position.x < LL.x)
{
position.x = UR.x - inset;
}
if (position.y > UR.y)
{
position.y = LL.y + inset;
}
if (position.y < LL.y)
{
position.y = UR.y - inset;
}
transform.position = position;
}
}
}