Im learning ThreeJS by extending the roller coaster example to add procedural track generation and random other features I thought would be fun.
Im currently having an issue trying to get the camera to follow the angle of the track as it banks in corners. If you ride the coaster in the demo below you can see how the camera doesnt bank. It stays perfectly horizontal.
Demo: https://il13yl.csb.app/
I have seen examples like these:
https://hofk.de/main/discourse.threejs/2021/MotionAlongCurve/MotionAlongCurve.html
https://hofk.de/main/discourse.threejs/2021/BasisToQuaternion/BasisToQuaternion.html
https://threejs.org/examples/#webgl_geometry_extrude_splines
But those are following the curves, whereas the roller coaster is following the geometry of the track.
I have tried to apply the logic used to build the geometry to the camera but that has some pretty crazy effects
point.copy(curve.getPointAt(i / divisions));
up.set(0, 1, 0);
forward.subVectors(point, prevPoint).normalize();
right.crossVectors(up, forward).normalize();
up.crossVectors(forward, right);
const angle = Math.atan2(forward.x, forward.z);
quaternion.setFromAxisAngle(up, angle);
Thanks in advance