I'm making an infinite runner game in Unity 3D. I have it so that platforms spawn and move backwards toward the player and they are destroyed once past the player. Over time when the platforms are spawned, the position they're spawned at gets more and more inaccurate. Sometimes they over lap slightly and sometimes there are small gaps in between them. And as the game is continuously played, it gets worse and worse. You can watch the video below to see what I mean. This is the script I use to spawn the object
public GameObject[] objectSpawned;
public PlatformKiller myPlatformKiller;
void Start()
{
myPlatformKiller = GameObject.Find("PlatformKiller").GetComponent<PlatformKiller>();
}
private void Update()
{
if (myPlatformKiller.readyForSpawn)
{
int rand = Random.Range(0, objectSpawned.Length);
Instantiate(objectSpawned[rand], transform.position, transform.rotation * Quaternion.Euler (-90f, 0f, 0f));
}
}
Here is a video so you can see what I'm talking about: https://youtu.be/eASouQlTsqs
Also, I know the exact unit size for each platform is 11.92. I know this because I added a c# script to each one that shows me the vector3 values. There are originally 20 platforms. And to know exactly where to spawn the object I did 11.92*20 = 238.4. And the first platform is at -4.78. So I subtracted that from 238.4 and got 233.62. So a z position of 233.62 is the correct place to spawn the object. I just wanted to include that in there so you know that the spawner gameobject is in the right place. Please let me know if there is any additional information about this that I can give you. Everything should theoretically work I think, so I seriously have no idea what to do. Thanks for your help!
readyForSpawn is set in my PlatformKiller script shown below:
public bool readyForSpawn;
void Update()
{
readyForSpawn = false;
}
void OnTriggerEnter(Collider target)
{
if (target.tag == "Floor")
{
readyForSpawn = true;
Destroy(target.gameObject);
}
}
readyForSpawn
and the movement speed of the platforms, and we can help you adjust either the time or position to compensate. \$\endgroup\$