猫史档案馆


尹子同款飞机!lolita大佬的最终级飞机代码!

用户:全能代码师全能代码师查看:11 回复:30 评论:11 创建时间:2022-01-03T13:56:24


/*友情声明:本代码为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);
}


回复

上一页1 页 / 共 1下一页
async_functionasync_function

啊我的飞机代码——

点赞0


评论


Stephan轩Stephan轩

终终终终终终终终终于有了

点赞0


评论


FML饭米粒FML饭米粒

你这发帖用的是python代码格式吧?

点赞3


评论


星辰Lolita星辰Lolita

还是别叫我(我的飞机都是两个模型的())这个和决战公海的比较像

点赞0


评论


银狐残影银狐残影

这串代码太棒了,但我想要哥斯拉皮肤代码,可以帮助一下我吗

点赞0


评论


IaeaIaea

nbnb

点赞0


评论


A332A332

顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶

点赞0


评论


肆秋肆秋

……你这个……这个大佬,他……他正经吗?

点赞0


评论


墨染云天墨染云天

imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%82%B9%E8%B5%9E.gif"alt="emotion_编程猫_点赞"

点赞0


评论


A332A332

顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶

点赞0


评论


A332A332

代码转过来了,怎么用?

点赞0


评论


未名用户未名用户

挖~

点赞0


评论


IaeaIaea

打卡打卡

点赞0


评论


全能代码师全能代码师

d d d

点赞0


评论


灵清帝王吃爆一切厕所灵清帝王吃爆一切厕所

挖坟啊

点赞0


评论


豹2a7豹2a7

我试了一下为啥看不见飞机呢,莫非是FPV飞行?

点赞1


评论


SCS_user_8yNg1LeFg6SCS_user_8yNg1LeFg6

挖坟(???)

点赞0


评论


yee剑走天下yee剑走天下

ddd

点赞0


评论


box3_创作喵box3_创作喵

收藏

点赞0


评论


318k318k

,,,

点赞0


评论


ฅ智慧编程猫ฅ----(和平工作室室长)ฅ智慧编程猫ฅ----(和平工作室室长)

e谁挖了)

点赞0


评论


蒋某人微操中外知晓蒋某人微操中外知晓

谁挖坟了

点赞0


评论


KL_LeoKL_Leo

https://box3.codemao.cn/e/eb9e4e25ffaaa775c436?p=lnfpWJ喵LSE04C4U0A2PD0KlmELlwXIOAQEn0WiLmA7qf9CyoMAVndWVzdA%3D%3D

点赞0


评论


KL_LeoKL_Leo

https://box3.codemao.cn/e/eb9e4e25ffaaa775c436?p=YJ9WYAQOiTlfVr%2BsD%2FFUUJm7ZSzVYYbwUNg7UbdRIaA7zNhi2oMAbnvJbovpE%3D

点赞0


评论


天空与风之者天空与风之者

怎么下飞机呢

 

点赞0


评论


伴雪纷飞伴雪纷飞

挖坟

点赞0


评论


喵喵咪awa喵喵咪awa

喵d

点赞0


评论


raearaea

挖()

点赞0


评论


卑微OIer卑微OIer

ddd

点赞0


评论


TAM无敌TAM无敌

哇 

点赞0


评论