猫史档案馆


【弓箭蓄力发射代码】代码教程

用户:全能代码师全能代码师查看:10 回复:26 评论:10 创建时间:2022-03-22T09:01:46


 

console.clear()
const zdQuat = new Box3Quaternion(0, 0, 0, 1)
async function shootGJ(entity, speed) {//射击弓箭
    var e = world.createEntity({
        mesh: 'mesh/箭.vb',
        position: entity.position.add(new Box3Vector3(0, 1, 0)),//防卡
        collides: true,//碰撞
        meshScale: new Box3Vector3(0.07, 0.07, 0.07),
        //gravity:true,
    })
    e.addTag('弓箭')
    e.zhongli = 0.1;
    var angle = Math.atan2(entity.player.facingDirection.z, entity.player.facingDirection.x)
    e.velocity.x = Math.cos(angle) * Math.cos(-entity.player.cameraPitch) * speed
    e.velocity.y = Math.sin(-entity.player.cameraPitch) * speed
    e.velocity.z = Math.sin(angle) * Math.cos(-entity.player.cameraPitch) * speed

    var orientation = zdQuat.rotateY(Math.atan2(e.velocity.z, e.velocity.x)).rotateX(-entity.player.cameraPitch)
    e.meshOrientation.copy(orientation)
    Object.assign(e, {
        particleRate: 30,
        particleLifetime: 3,
    })

    e.onEntityContact(({ other }) => {
        if (other.isPlayer && other != entity) {
            other.hurt(10 + speed * 2)
        }
        e.destroy()
    })
    e.onVoxelContact(({ }) => {
        e.destroy()
    })
    await sleep(15000);
    e.destroy()
}
(async function(){
    for(let i = 0;i<Infinity;i++){
        world.querySelectorAll('.弓箭').forEach((e)=>{
            e.velocity.y -= e.zhongli
        })
        await sleep(100)
    }
})()
world.onPlayerJoin(({ entity }) => {
    entity.enableDamage = true;
})
world.onPress(async ({ entity, button }) => {
    if (button == Box3ButtonType.ACTION0) {
        var speed = 1
        entity.player.walkState *= 0.5;
        entity.player.walkAcceleration *= 0.5;
        entity.player.runSpeed *= 0.5;
        entity.player.runAcceleration *= 0.5;
        while (entity.player.action0Button) {
            if (speed < 10) {
                speed++
            }
            await sleep(500);
            entity.player.directMessage('蓄力:' + speed + '/10')
        }
        shootGJ(entity, speed)
        entity.player.walkState *= 2;
        entity.player.walkAcceleration *= 2;
        entity.player.runSpeed *= 2;
        entity.player.runAcceleration *= 2;
    }
})

ps:改重力则改e.zhongli,改速度改speed


回复

上一页1 页 / 共 1下一页
云游box3der尖头叉子云游box3der尖头叉子

沙发

点赞0


评论


指令者指令者

龙椅

 

点赞0


评论


Architect_皮卡awaArchitect_皮卡awa

axxemotion_doge

点赞0


评论


未名用户未名用户

👀👀👀

点赞0


评论


egg鸡蛋蛋egg鸡蛋蛋

进收藏夹吃灰

点赞0


评论


YDS尹子YDS尹子

cameraPitch是啥为啥我不知道()()

点赞0


评论


传奇无敌传奇无敌

你可知无限火力弓箭代码?()()()(

点赞0


评论


传奇无敌传奇无敌

这段代码的弓箭位置和伤害效果会不理想,因为撞到玩家会有延迟,所以会有奇怪的击退和不精准的命中,而且y坐标+1会使射不到近距离目标,因使用碰撞过滤加上碰撞箱检测搭配高速循环对弓箭的伤害进行判断,这样效果会更好

点赞0


评论


小白鸡小白鸡

顶一下

点赞0


评论


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

收藏

点赞0


评论


若潇羽少若潇羽少

收藏()

点赞0


评论


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

收藏*2

点赞0


评论


蓝矮爱乐蓝矮爱乐

借鉴你的代码

做了个不用onPress就可以获取焦点位置的代码()

点赞0


评论


幕川北幕川北

事情是这样的:

这个男人叫小明他还是一如既往的打着代码

center_image

突然一个bug难住了ta请各位大佬教教ta下面的问题如何解决

 

center_image

是个聪明人都会发现一个问题:

nnd!!!!为神喵弹从他的身体穿了过去!

people1:人物开了碰撞吗

我:神岛默认人物开启碰撞

people2:速度是不是太快了

我:速度调了speed=1还不慢吗。。。。。

people3:子弹开了碰撞吗?

我:我开了子弹碰撞

 

请各位大佬帮助我吧!!!!!!

呜呜TwT我太难了啊啊啊

center_imagecenter_image

 

点赞1


评论


无极玄天无极玄天

进收藏夹吃灰

点赞0


评论


屑怪盗屑怪盗

收藏

点赞0


评论


千星河凉月吖千星河凉月吖

额额额

点赞0


评论


alopdopsalopdops

收藏

点赞0


评论


收藏(((

点赞0


评论


WitheredWonderWitheredWonder

666)

点赞0


评论


追梦ez追梦ez

夹吃灰

点赞0


评论


宇之尘埃宇之尘埃

收藏

点赞0


评论


锦衣侠客锦衣侠客

666

点赞0


评论


搬码喵搬码喵

我问问为啥是Python

点赞0


评论


小屑鹿小屑鹿

👀

点赞0


评论


JerryM4OJerryM4O

考古

点赞0


评论