You're currently using a static or hardcoded value for scrollPosition. Instead, you should calculate it based on the clicked item's position relative to the carousel and its width. This will ensure the clicked item is centered correctly.
const scrollPosition = itemOffset - (carouselWidth / 2) + (itemWidth / 2);
Please give it a try and let me know if it works