Move camera back and forth on wheel event along catmullromcurve3 : HELP :((((

Hello there! So. I am building something where the user scrolls up and down (forwards and backwards) through a route (thing is… user has to go through specific points, I’ve defined these along a catmullromcurve3). I’ve looked at a bunch of examples related to this already, and messed about with the code in all possible ways (clearly not all…), but can’t get it quite there.

Right now, it kinda works (ish) : it goes back and forth on scroll but on what seem to be random points along the curve, which upon every scroll back and forth change every time?

Any tips/help much much appreciated. Many thanks in advance <3 . Here’s the part of the code where I’m defining the curve and wheel event:

//curve

spline = new THREE.CatmullRomCurve3( [

            new THREE.Vector3(0,0,50),

            new THREE.Vector3(0,0,20),

            new THREE.Vector3(5,0,0),

            new THREE.Vector3(-5,0,-10)

        ]);

        const points = spline.getPoints(50);

        const geometry = new THREE.BufferGeometry().setFromPoints(points);

        // scroll controls, following curve

        window.addEventListener("wheel", onMouseWheel);

        var camPosIndex = 0;              

       function onMouseWheel(event)

        {

         camPosIndex++;

        if (event.deltaY > 0){

           var camPos = spline.getPoint(camPosIndex / 100);

                  camera.position.x = camPos.x ;

                  camera.position.y = camPos.y;

                  camera.position.z +=  event.deltaY * 0.01;

                 camera.rotation.x = camRot.x;

                 camera.rotation.y = camRot.y;

                 camera.rotation.z = camRot.z;

           camera.lookAt(spline.getPoint((camPosIndex+1) / 10000));
       }

           else if (event.deltaY<0)

            {

            var camPos = spline.getPoint(camPosIndex / 100 );
              
                  camera.position.x =  camPos.x ;

                  camera.position.y =   camPos.y ;

                  camera.position.z +=  event.deltaY * 0.01;

                camera.rotation.x = camRot.x;

               camera.rotation.y = camRot.y;

                camera.rotation.z = camRot.z;

           camera.lookAt(spline.getPoint((camPosIndex+1) / 10000));

          }

          update();

         }