猫史档案馆


测试成功!意外啊!

用户:白水WhiteWater点猫账号专门发帖白水WhiteWater点猫账号专门发帖查看:0 回复:1 评论:0 创建时间:2023-03-13T18:27:56


话不多说,上图()()()()()

center_image

 

是不是很xvan呢,打这个就行!

就是吉吉喵der年兽,改了一下!

const lions = world.querySelectorAll('#会移动的测试物');//小年兽的模型名称叫做'狮子-1'
lions[0].collides = true; // 开启碰撞
lions[0].gravity = true; // 开启重力
lions[0].friction = 0; // 关闭摩擦力

// 创建一堆相同的实体并push到lions中
for (let i = 0; i < 30; i++) {
    const e = world.createEntity(lions[0]);
    e.position.y += Math.random() * 50; // 随机高度, 防止弹飞
    e.maxHp = 999999
    e.hp = 999999
    e.enableInteract=true; 
    e.interactRadius=128
    e.interactHint = e.id; // 互动提示框显示实体的名称
    e.interactColor = new Box3RGBColor(Math.random()*1,Math.random()*1,Math.random()*1);
    lions.push(e);
}

// onTick中处理实体的运动
world.onTick(() => {
    // 处理每个实体
    lions.forEach((e) => {
        // 计算X和Z轴方向的速度的和
        const sdxz = Math.abs(e.velocity.x) + Math.abs(e.velocity.z);
        if (sdxz > 0.1) {
            // sdxz大于一, 判定为运动中
            // 计算当前方向
            const angle = Math.floor(Math.atan2(e.velocity.z, e.velocity.x) / (2. * Math.PI) * 256) * 2. * Math.PI / 256;
            // 设置朝向, 如0果朝向不对, 可自行在后面添加相应的rotateX/rotateY/rotateZ
            const orientation = new Box3Quaternion(0, 0, 0, 1).rotateY(angle).rotateY(Math.PI/-1);
            e.meshOrientation.copy(orientation);
        } else {
            // 随机角度
            const randTheta = Math.random() * Math.PI * 2;
            // 随机速度大小
            const mag = Math.random() + Math.random();
            // 设置速度
            e.velocity.x = mag * Math.sin(randTheta);
            e.velocity.z = mag * Math.cos(randTheta);
            // 跳一下
            if (e.velocity.y < 1) {
                e.velocity.y += 0.5;
            }
        }
    });
}); 
for (let x = 0; x < 126; x++) {
    for (let y = 9; y < 20; y++) {
        voxels.setVoxel(x, y, 0, 'stone')
        voxels.setVoxel(x, y, 125, 'stone')
    }
}
for (let z = 0; z < 126; z++) {
    for (let y = 9; y < 20; y++) {
        voxels.setVoxel(0, y, z, 'stone')
        voxels.setVoxel(125, y, z, 'stone')
    }
}


回复

上一页1 页 / 共 1下一页
白水WhiteWater点猫账号专门发帖白水WhiteWater点猫账号专门发帖

非战术核显卡勿逝!

center_image

点赞0


评论