首页 > 解决方案 > TypeError:THREE.Math.lerp 不是函数

问题描述

我正在搜索 WEBGL Three.js Games 的在线参考资料。遇到了一款游戏,它的源代码对于提供它的人来说可以正常工作,但我遇到了一个错误

TypeError:THREE.Math.lerp 不是函数

使用此函数的代码段是:

function update(){
    //stats.update();
    //animate
    rollingGroundSphere.rotation.x += rollingSpeed;
    heroSphere.rotation.x -= heroRollingSpeed;
    if(heroSphere.position.y<=heroBaseY){
        jumping=false;
        bounceValue=(Math.random()*0.04)+0.005;
    }
    heroSphere.position.y+=bounceValue;
    heroSphere.position.x=THREE.Math.lerp(heroSphere.position.x,currentLane, 2*clock.getDelta());//clock.getElapsedTime());
    bounceValue-=gravity;
    if(clock.getElapsedTime()>treeReleaseInterval){
        clock.start();
        addPathTree();
        if(!hasCollided){
            score+=2*treeReleaseInterval;
            scoreText.innerHTML=score.toString();
        }
    }
    doTreeLogic();
    doExplosionLogic();
    render();
    requestAnimationFrame(update);//request next update
}

标签: graphicsthree.js

解决方案


Math已重命名为MathUtilswith r113。所以试试下面的代码:

heroSphere.position.x=THREE.MathUtils.lerp(heroSphere.position.x,currentLane, 2*clock.getDelta());//clock.getElapsedTime());

推荐阅读