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.
I have seen examples like these:
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