I'm doing the exact same thing in my game.
I've used a 3x3 grid and added darkness (fog) of war so the player cannot see copies of herself/himself.
Here's the old [video][1]. I've since resolved a paradox (with different code than what you'll see later in this answer).
For the most part, it's just Asteroids (1979). You just subtract the height of the map if the player is too far up, add the map height if they are too far down, and similarly for the width.
Copying objects is a must:
1. Never render copies of the player (you might want to keep the object for AI).
2. Render only the nearest enemy (and make that enemy fade in and out whenever rendering a new instance of that enemy).
3. Always render copies of non-static objects (cars, breakables)
4. Always render bullet trails and decals.
The collisions should be calculated only on the original map (and not the extraneous ones).
AI is a really hard question, and you will likely have to use calculations based on all of the copies of the AI, not just the original (since there will likely be more than one instance). I'm lucky, I don't have to deal with AI.
#pragma strict
var trans : Transform;
var delta : float = 0.01;
function Start ()
{
var obj : GameObject = GameObject.Find("/Character");
trans = obj.GetComponent(Transform);
}
function Update ()
{
Warp();
}
function Warp ()
{
if(trans.position.x > 100)
{
trans.position.x -= 200;
Switch();
}
else if(trans.position.x < -100)
{
trans.position.x += 200;
Switch();
}
if(trans.position.z > 100)
{
trans.position.z -= 200;
Switch();
}
else if(trans.position.z < -100)
{
trans.position.z += 200;
Switch();
}
}
function Switch ()
{
trans.position.y += delta;
//if(trans.position.y > 0) trans.position.y -= (2000 - delta);
//else trans.position.y += (2000 + delta);
}
[1]: http://www.youtube.com/watch?v=MByNXzQQYto
The problem with my answer is it is highly entangled with the rest of the design of my FPS, so ask questions.
[edit:]
Sorry on the extremely late response.
You seem to have hit the nail on the head on the solution. Sure it can be a little difficult to debug things with the 3x3 world, but for the most part any issue can be resolved.
I've added nice editor script to my game that tiles stuff procedurally. I actually catered the code to the project you are making since my project involves two worlds.
Simply add the script to your game and notice that under the edit tab you have a new tile button on the very bottom.
Simply select all the objects you want to duplicate and hit edit-->tile and they will be recreated without any redundancies (basically I don't overlap the original with a new copy that's exactly the same).
class TileWorld extends Editor
{
@MenuItem("Edit/Tile")
static function Tile(command : MenuCommand)
{
var tileLength : int = 3;
var mapHeight : float = 5000;
var mapWidth : float = 5000;
//Make sure the center tile (1) will have evenly distributed tiles on each side (2n) aka [2n + 1] aka ODD
if(tileLength % 2 == 0 || tileLength < 1)
{
Debug.LogError("Currently an even/zero/negative number of tiles, try an odd/non-zero/positve number");
return; //Important!
}
//This makes EVERYTHING//
for(var c : int = 0; c < Selection.transforms.Length; c++) //cycle through all selected gameobjects.
{
//Debug.Log(c);
var obj : GameObject;
obj = Selection.gameObjects[c];
var normal : Transform; //The transform being manipulated
normal = Instantiate(obj.transform);
//find the max distance away from the center segment
var x : float;
var z : float;
x = mapWidth*-1.0f*(tileLength - 1)/2; //start in South-West corner of the map (-x,-z as viewed from the sky)
z = mapHeight*-1.0f*(tileLength - 1)/2;
var tx : float;
var tz : float;
tx = x;
//Start//
for(var i : int = 0; i < tileLength; i++)
{
tz = z;
for(var j : int = 0; j < tileLength; j++)
{
if(i == tileLength - (tileLength - 1)/2 - 1)
{
if(j == i)
{
//Debug.Log(i + " " + j);
tz += mapHeight;
continue;
}
}
Instantiate(obj,normal.position + Vector3(tx,0,tz),normal.rotation);
tz += mapHeight;
}
tx += mapWidth;
}
//Clean Up//
obj = null;
DestroyImmediate(normal.gameObject);
//END//
}
}
}
↧