- Home /
Question by
danyx1980 · Nov 27, 2017 at 06:59 PM ·
platformerinfinite terrain
Moving an object adjacent to another one
I'm trying to make a sort of infinite runner where there's always a floor below the character, the way I've been generating it is by moving the tiles that get offscreen to the other side and simply reusing them, problem is this isn't particularly random, can sometimes create gaps between tiles and is using hardcoded values, Since tiles have different widths I can't just use a single spawn point for each one., like so:
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == "Tile")
other.gameObject.transform.position = new Vector3(21, 10, -4);
if (other.gameObject.name == "Bridge")
other.gameObject.transform.position = new Vector3(26.5f, 10, -4);
}
Is there a way to more effectively create this effect? Would it be better to destroy the objects that go out of screen and create new ones on the other end?
Comment