I am trying to create the appearance of a never ending field. When an object that is moving gets close to the boundary, I want to create a clone of it and set it at the other end of the field. I do not want to destroy the object until it is out of view range. So, at x>750 I clone the object to x-1500 then, when the player hits 1000, I poof him to -1000 (actually move him back 2000) Finally when an object hits 1500, I destroy the object.
Here is the code for the object, which is causing the problem:
if (transform.position.x > 750)
{
if (newx == 0)
{
Instantiate(gameObject, new Vector3(transform.position.x - 1500, transform.position.y, transform.position.z), Quaternion.identity);
newx = 1;
}
}
if (transform.position.x < -750)
{
if (newx == 0)
{
Instantiate(gameObject, new Vector3(transform.position.x + 1500, transform.position.y, transform.position.z), Quaternion.identity);
newx = 1;
}
}
if (transform.position.x > 1500)
{
Destroy(gameObject);
}
if (transform.position.x < -1500)
{
Destroy(gameObject);
}
It appears that everything past 750 is gone. (there should be objects there between 750 and 1500)
Am I missing something?
btw the newx statements are so I only clone that particular object once per boundary cross. I also have the exact same code for y and z axes.
Finally, since I can not tell because objects disappear, does movement (such as the addrelativeforce) transfer to the new clone, or do I have to pass that as well?