猫史档案馆


求助飞机代码

用户:winner瑾恒winner瑾恒查看:1 回复:2 评论:1 创建时间:2022-05-07T20:34:35


如何做效果(交互后开飞机)box3,提供者将获得10000000哈农币(可用于哈哈农场交易)官方的


回复

上一页1 页 / 共 1下一页
SCS_user_Ro5e1laikiSCS_user_Ro5e1laiki

我会,发链接

点赞0


评论


bianchbianch

/*友情声明:本代码为Lolita原创!在这里我只是转载!如果要使用代码,请标明原作者Lolita!*/ 
function drive1(entity) {
    let angle1 = entity.direction;
    if (angle1 < 0) {
        angle1 = PI2 + angle1;
    }
    if (entity.angle < 0) {
        entity.angle = PI2 + entity.angle;
    }
    entity.angle %= PI2;
    const angle2 = entity.angle;
    if (Math.min(Math.abs(angle1 - angle2), Math.abs(PI2 - angle1 + angle2)) < 0.1) {
        entity.angle = entity.direction;
        return undefined;
    } else {
        if (angle1 > angle2) {
            if (angle1 - angle2 < Math.PI) {
                entity.angle += 0.1;
                return 0;
            } else {
                entity.angle -= 0.1;
                return 1;
            }
        } else {
            if (angle1 + (PI2 - angle2) < Math.PI) {
                entity.angle += 0.1;
                return 0;
            } else {
                entity.angle -= 0.1;
                return 1;
            }
        }
    }
}
const PI2 = Math.PI * 2

console.clear()
const planes = []
world.onPlayerJoin(({ entity }) => {
    const plane = world.createEntity({
        mesh: 'mesh/飞机.vb',
        collides: true,//碰撞
        gravity: false,//重力
        position: new Box3Vector3(喵, 喵, 喵),
        meshScale: new Box3Vector3(0.02, 0.02, 0.02),
    });
    plane.angle = 0;//玩家视角角度
    plane.direction = 0;
    plane.rotateX = 0;
    entity.plane = plane;
    planes.push(plane)
    entity.up = 0;
    plane.speed = 1;//自己调整速度
    plane.rotateZ = 0;
    plane.angle = Math.atan2(entity.player.facingDirection.z,entity.player.facingDirection.x);
    entity.player.cameraEntity = plane
    entity.player.invisible = true;
    entity.player.spectator = true;
});
world.onTick(({ tick }) => {
    world.querySelectorAll('player').forEach((x) => {
        drive(x, x.plane)
    })
})
const plane_Quat = new Box3Quaternion(0, 0, 0, 1);
async function drive(entity, plane) {//太难解释了
    if (entity.player.jumpButton == true) {
        if (entity.up > -0.8) {
            entity.up -= 0.1
        }
    }
    if (entity.player.crouchButton == true) {
        if (entity.up < 0.8) {
            entity.up += 0.1
        }
    }
    plane.direction = Math.atan2(entity.player.facingDirection.z, entity.player.facingDirection.x)
    const num = drive1(plane);
    if (num === 1) {//右
        if (plane.rotateZ < 1) {//在这段代码中,-1和1为飞机转弯系数,系数越大能力越好
            plane.rotateZ += 0.1
        } else {
            plane.rotateZ = 1;
        }
    } else if (num === 0) {//左
        if (plane.rotateZ > -1) {
            plane.rotateZ -= 0.1
        } else {
            plane.rotateZ = -1;
        }
    } else if (num == undefined) {
        plane.rotateZ *= 0.95;
    }
    plane.velocity.set(Math.cos(plane.angle) * Math.cos(entity.up) * plane.speed, -Math.sin(entity.up) * plane.speed, Math.sin(plane.angle) * Math.cos(entity.up) * plane.speed);
    plane.meshOrientation = plane_Quat.rotateY(Math.PI * 0.5).rotateZ(plane.rotateZ).rotateX(-entity.up).rotateY(plane.angle);
}

点赞0


评论