- Home /
Infinite Road Generation using Colliders, is this wrong?
I'm working on a racing game where the track is generated as the player zooms along it. I'm using an algorithm that places pieces of road in front of other pieces and then recycles the far-behind pieces.
The vehicle is a rigidbody, and when it goes across the ever-so-small gap (at a great speed) between two pieces, say, Piece 12 and Piece 13, the vehicle's front falls slightly down and clips the edge of Piece 13 so hard that it flies up into the air and the player dies.
Is there a better and more efficient way of doing this? Like terrain generation or a Grand Unified Big Box Collider?
EDIT Each track piece is 500 units long, and here's the code:
public class TrackGenerator : MonoBehaviour
{
public static int trackCount;
private bool slowmo;
private int random, random2;
private List<GameObject> trackPieces;
public GameObject TrackVariant1;
void Start()
{
trackPieces = new List<GameObject>();
// Generates 50 peices of track as a starting point.
//(Each track piece is 500 units long)
for (int y = 0; y < 50; y++)
{
trackCount++;
trackPieces.Add(TrackVariant1);
GameObject x = Instantiate(trackPieces[y], new Vector3(0, 0, y * 500), Quaternion.identity) as GameObject;
trackPieces[y].transform.parent = gameObject.transform;
}
}
}
There is no reason why a gap of any size should exist, if you are generating the road the right way. But without seeing your current mesh collider appending script, there's no telling what you're doing wrong.
Your answer
![](https://koobas.hobune.stream/wayback/20220613125454im_/https://answers.unity.com/themes/thub/images/avi.jpg)