To create a smooth coaster track I am creating the XZ paths separately (custom bspline script) and combining them with the changes in the Y axis.

```
let cords = [];
let cxz, cy, pr;
let pi2 = Math.PI * 2;
for (let t = 0; t < 1; t += 0.001) {
cxz = bspline(t * xzMaxT, xzDegree, xzPoints);
pr = t * pi2;
cy = Math.cos(pr * 10) * 2 + Math.sin(pr * 17) * 2 + 5;
cords.push(vector.set(cxz[0], cy, cxz[1]).clone().multiplyScalar(2.5));
}
return new THREE.CatmullRomCurve3(cords, true, "chordal", 0);
```

I found this creates a really smooth track

**smooth demo:** https://unl0hl.csb.app/

However, it has a big drawback. The bspline script Im using is set to create closed path. If the distance between the last point and the first point is far, the Y between those points seems to be getting stretched and results in the last section of track being long and flat (see pic below)

To try and fix this issue, I extended CatmullRomCurve3:

```
(function () {
class TrackCurve extends THREE.CatmullRomCurve3 {
constructor(points, closed, curveType, tension) {
super(points, closed, curveType, tension);
this.pi2 = Math.PI * 2;
}
getPointAt(t, optionalTarget = new THREE.Vector3()) {
super.getPointAt(t, optionalTarget);
let pr = t * this.pi2;
optionalTarget.y = Math.cos(pr * 10) * 2 + Math.sin(pr * 17) * 2 + 5;
return optionalTarget.multiplyScalar(2.5);
}
}
THREE.TrackCurve = TrackCurve;
})();
```

and used it like so:

```
function buildCurve() {
// The number of control points without the last repeated
// points
let xzOriginalNumPoints = xzPoints.length - (xzDegree + 1);
let xzMaxT = 1.0 - 1.0 / (xzOriginalNumPoints + 1);
let cords = [];
let cxz;
for (let t = 0; t < 1; t += 0.001) {
cxz = bspline(t * xzMaxT, xzDegree, xzPoints);
cords.push(vector.set(cxz[0], 0, cxz[1]).clone());
}
return new THREE.TrackCurve(cords, true, "chordal", 0);
}
```

This solves the issue of the long flat section of track but it creates violent bumps in the curve and I have no idea why:

**bumpy demo:** https://1xk2ej.csb.app/

My goal is to solve the long flat section of track issue and have a really smooth ride without removing the use of the bspline script. I have exhausted solutions with my limited knowledge base.

Thanks in advance for any help