- Home /
Generating an infinite road from 3 preFabs
Hi, I'm making a runner game, the road is composed of 3 pieces, A,B,C.
To save memory, I'm trying to avoid making a road made from 5000 pieces, and instead, 3 pieces that every-time you finish one, it moves to the next place.
To be more clear, a runner and 3 road pieces that follow it.
Every road has a trigger at the end, this is what calls the function that moves one of the roads to the next position and puts the old one in "Roads space" where it waits to be moved again.
This picture explains how it works:
I can handle the random choosing, and I can handle the putting back to roads space, however I can't find a way to put the road in the next position where it should be attached to the current road, because the runner is moving, and the x position is changing :/ Please help
position = previousRoad.position + Vector3(previousRoad.length, 0, 0);
Does that help?
It seems like you might could get the position of the current road section and add some offset to that. You might have to do a different offset based on what road you are on now and what road you are going to
Answer by jacobschellenberg · Jul 30, 2013 at 07:02 PM
Attach it to the end point of the current road by using an empty gameobject placed in the proper connecting/end point position. When the road is to be reattached to the next road, it asks for the endpoint position of the current road, which is just an empty gameObject, this empty object should be a part of the road prefab.