I think that the key is not to work with moving your object to a set point, but to an offset that compensates. This negates innacuracy .
Here's my solution to a 3D tiling infinite landscape, and it works very well...
public static Vector3 RepeatPos (Vector3 nPos){
Vector3 vPos=nPos;
if(gTiling){
if(gGoody!=null){
Vector3 vDelta=vPos-goodyScript.GetPos();
if (vDelta.x>gMaxDist){
vPos.x-=gMazWid;
}else if(vDelta.x<-gMaxDist){
vPos.x+=gMazWid;
}
if (vDelta.z>gMaxDist){
vPos.z-=gMazWid;
}else if(vDelta.z<-gMaxDist){
vPos.z+=gMazWid;
}
}
}
return (vPos);
}
This is called by any object that needs to tile, and does not reference time at all.
note: gmazwid is just a number and gmaxdist is exactly half, so it basically moves any object that you've gone a certain distance away to the other side in 3D space.
-----further notes.....
As a note: the original question sounds like all that is needed is minor changes as hinted above... The solution posted is an example of tiling that looks ok from all angles, not just firing down one given axis, so...
simpler solution for 2D tiling:
if(transform.position.x<=0){
transform.position.x+=gMaxDist;
}
instead of
"transform.position.x=gMaxDist;" which would result in gaps and offsets.
the other code above does work, but depends on all the above variables being set and accessible, and is "fully 3D".
firstly this behaviour should belong somewhere like in a "gamescript", as if you use it, you'll use it a hell of a lot.
try replacing my "goodyScript.GetPos()" with the goody's transform.position somehow (that's all "GetPos()" returns from the goodyscript), you could have a static "Pos" variable in the goody.
You'll also need to set your gMazwid and gMaxDist (gMazWid is the entire size of your level, and gMaxDist is half of gMazWid (only there to save on typing).
Your tiling objects will need the following code in the Udate function.
transform.position=WhatEverMyScrtiptIsCalled.RepeatPos(transform.position);