снова проподает пол туловища в маленьком червяке я не знаю в чем дело

<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title>3D Червяк</title>
    <style>
        body { margin: 0; overflow: hidden; }
        #menu {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.8);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            z-index: 10;
        }
        #menu h1 { margin-bottom: 20px; }
        #menu label { margin-bottom: 10px; }
        #menu button { padding: 10px 20px; font-size: 16px; }
        #score {
            position: absolute;
            top: 10px;
            left: 10px;
            color: white;
            font-size: 24px;
            z-index: 5;
        }
    </style>
</head>
<body>
    <div id="menu">
        <h1>Выберите настройки червяка</h1>
        <label>
            Выберите тип червяка:
            <select id="snakeType">
                <option value="default">Обычный червяк</option>
                <option value="textured">Червяк с текстурами</option>
            </select>
        </label>
        <div id="colorPicker">
            <label>
                Выберите цвет червяка:
                <input type="color" id="snakeColor" value="#FFFF00">
            </label>
        </div>
        <div id="textureUploader" style="display: none;">
            <label>
                Загрузите изображение для текстуры:
                <input type="file" id="textureFile" accept="image/png, image/jpeg">
            </label>
        </div>
        <button id="startButton">Начать игру</button>
    </div>

    <div id="score">Счет: 0</div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
    <script>
        let scene, camera, renderer;
        let wormMesh, pathPoints = [];
        let direction = new THREE.Vector3(0, 0, -1);
        let speed = 0.1;
        let food;
        let keyStates = {};
        let maxPoints = 10; // Червяк начнет с 10 сегментов
        const radius = 0.25; // Размер червяка
        const radialSegments = 8;
        const closed = false;
        let score = 0;

        document.getElementById('snakeType').addEventListener('change', function() {
            const snakeType = this.value;
            document.getElementById('textureUploader').style.display = snakeType === 'textured' ? 'block' : 'none';
            document.getElementById('colorPicker').style.display = snakeType === 'default' ? 'block' : 'none';
        });

        document.getElementById('startButton').addEventListener('click', function() {
            const snakeType = document.getElementById('snakeType').value;
            const snakeColor = document.getElementById('snakeColor').value;
            const textureFile = document.getElementById('textureFile').files[0];
            document.getElementById('menu').style.display = 'none';
            init(snakeType, snakeColor, textureFile);
        });

        function init(snakeType, snakeColor, textureFile) {
            scene = new THREE.Scene();
            scene.background = new THREE.Color(0x87CEEB);

            camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
            camera.position.y = 5;
            camera.position.z = 10;

            renderer = new THREE.WebGLRenderer({ antialias: true });
            renderer.setSize(window.innerWidth, window.innerHeight);
            document.body.appendChild(renderer.domElement);

            const light = new THREE.AmbientLight(0xffffff, 0.5);
            scene.add(light);

            const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
            directionalLight.position.set(0, 10, 0);
            scene.add(directionalLight);

            const groundGeometry = new THREE.PlaneGeometry(100, 100);
            const groundMaterial = new THREE.MeshStandardMaterial({ color: 0x008000 });
            const ground = new THREE.Mesh(groundGeometry, groundMaterial);
            ground.rotation.x = -Math.PI / 2;
            scene.add(ground);

            if (snakeType === 'textured' && textureFile) {
                const reader = new FileReader();
                reader.onload = function(event) {
                    const textureLoader = new THREE.TextureLoader();
                    textureLoader.load(event.target.result, function(texture) {
                        createSnake(snakeType, snakeColor, texture);
                        createFood();
                        animate();
                    });
                };
                reader.readAsDataURL(textureFile);
            } else {
                createSnake(snakeType, snakeColor, null);
                createFood();
                animate();
            }

            document.addEventListener('keydown', onKeyDown);
            document.addEventListener('keyup', onKeyUp);
            window.addEventListener('resize', onWindowResize);
        }

        function createSnake(snakeType, snakeColor, texture) {
            pathPoints = [];
            const initialPosition = new THREE.Vector3(0, 0.5, 0);

            // Располагаем точки на некотором расстоянии друг от друга
            for (let i = 0; i < maxPoints; i++) {
                const point = initialPosition.clone().sub(direction.clone().multiplyScalar(i * speed * 5)); // Увеличиваем расстояние между точками
                pathPoints.push(point);
            }

            const wormCurve = new THREE.CatmullRomCurve3(pathPoints);
            const tubularSegments = 100; // Фиксированное значение
            const geometry = new THREE.TubeGeometry(
                wormCurve,
                tubularSegments,
                radius,
                radialSegments,
                closed
            );

            let material;
            if (snakeType === 'textured' && texture) {
                material = new THREE.MeshStandardMaterial({ map: texture });
            } else {
                material = new THREE.MeshStandardMaterial({ color: snakeColor });
            }

            wormMesh = new THREE.Mesh(geometry, material);
            scene.add(wormMesh);

            snake = { position: initialPosition.clone() };
        }

        function createFood() {
            const geometry = new THREE.SphereGeometry(0.5, 16, 16);
            const material = new THREE.MeshStandardMaterial({ color: 0xff0000 });
            food = new THREE.Mesh(geometry, material);
            food.position.set(
                Math.floor(Math.random() * 20 - 10),
                0.5,
                Math.floor(Math.random() * 20 - 10)
            );
            scene.add(food);
        }

        function onKeyDown(event) { keyStates[event.code] = true; }
        function onKeyUp(event) { keyStates[event.code] = false; }

        function updateDirection() {
            const turnSpeed = 0.05;
            if (keyStates['KeyA']) direction.applyAxisAngle(new THREE.Vector3(0, 1, 0), turnSpeed);
            if (keyStates['KeyD']) direction.applyAxisAngle(new THREE.Vector3(0, 1, 0), -turnSpeed);
            direction.normalize();
        }

        function animate() {
            requestAnimationFrame(animate);

            updateDirection();

            let currentSpeed = speed;
            if (keyStates['KeyW']) currentSpeed = speed * 1.5;
            if (keyStates['KeyS']) currentSpeed = speed * 0.5;

            const newPosition = snake.position.clone().add(direction.clone().multiplyScalar(currentSpeed));
            newPosition.y = 0.5;
            snake.position.copy(newPosition);

            pathPoints.push(snake.position.clone());
            if (pathPoints.length > maxPoints) {
                pathPoints.shift();
            }

            const wormCurve = new THREE.CatmullRomCurve3(pathPoints);
            const tubularSegments = 100; // Фиксированное значение для плавной отрисовки
            wormMesh.geometry.dispose();
            wormMesh.geometry = new THREE.TubeGeometry(
                wormCurve,
                tubularSegments,
                radius,
                radialSegments,
                closed
            );

            if (snake.position.distanceTo(food.position) < 1) {
                scene.remove(food);
                createFood();
                maxPoints += 5; // Увеличиваем максимальную длину
                score += 10;
                document.getElementById('score').textContent = `Счет: ${score}`;
            }

            const cameraOffset = direction.clone().multiplyScalar(-10).add(new THREE.Vector3(0, 5, 0));
            camera.position.lerp(snake.position.clone().add(cameraOffset), 0.1);
            camera.lookAt(snake.position);

            renderer.render(scene, camera);
        }

        function onWindowResize() {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
        }
    </script>
</body>
</html>