猫史档案馆


【Box3】自动跳跃代码

用户:龙的传人_龙的传人_查看:9 回复:4 评论:9 创建时间:2020-11-12T21:39:18


这个Box3的延迟很严重,

为了保证延迟不会影响到自动跳跃,

我用的不是world.onVoxelContact(),

而是判断玩家四周是否有方块(利用坐标的误差抵消延迟的时间)。

代码:

function autojump(){
    var x1,x2,z1,z2,y;
    world.onTick(()=>{
        world.querySelectorAll('player').forEach((entity)=>{
            for(x1=Math.round(entity.position.x-1);x1<=Math.round(entity.position.x+1);x1++){
                for(z1=Math.round(entity.position.z-1);z1<=Math.round(entity.position.z+1);z1++){
                    for(x2=Math.floor(entity.position.x-0.5);x2<=Math.ceil(entity.position.x-0.5);x2++){
                        for(z2=Math.floor(entity.position.z-0.5);z2<=Math.ceil(entity.position.z-0.5);z2++){
                            y=Math.round(entity.position.y-0.5);
                            if(voxels.getVoxelId(x2,y,z2)!=0){
                                entity.position.y+=2;
                            }
                        }
                    }
                }
            }
        })
    })
}

玩家大小≥1时无法触发自动跳跃,

所以要设置玩家大小:

world.onPlayerJoin(({entity})=>{
    entity.player.scale=0.8;
})

这个代码有一些bug,

甚至2格都可以跳上,

但是作为一名非常不容易的programmer来说,

饶了我吧……


回复

上一页1 页 / 共 1下一页
白篮白篮

emotion_编程猫_点赞

点赞0


评论


传奇无敌传奇无敌

entity.position.y+=2改一改就行了

点赞0


评论


治愈绾兮治愈绾兮

好复杂...就不能简化吗

world.onVoxelContact(({entity,axis,x,y,z}) => {
    if(entity.isPlayer){
        if(axis.y < 1 && axis.y > -1){
            if(voxels.getVoxelId(x,y+1,z) == voxels.id('air')){
                entity.velocity.y = 0.75;
            }
        }
    }
});

点赞0


评论


夜影行者夜影行者

收藏

点赞0


评论