猫史档案馆


跑酷激光教程

用户:星辰Lolita星辰Lolita查看:36 回复:22 评论:36 创建时间:2021-07-22T15:23:15


有些时候跑酷会用到激光

就是那种碰到激光就喵的

首先

喵家实体的enableDamage设为true

然后创建一个模型

模型大小是:16 1 1

然后写一个函数

function addlaser(start,end){
    const distance = start.distance(end);
    const laser = world.createEntity({
        mesh: 'mesh/激光.vb',
        meshScale: [0.0625*distance,0.0625,0.0625],
        gravity: false,
        collides: false,
        fixed: true,
        position: start.lerp(end,0.5),
    })
    const d = start.sub(end);
    laser.meshOrientation = Quat.rotateX(Math.atan2(d.y,Math.sqrt(d.x**2+d.z))).rotateY(Math.atan2(d.z,d.x));
    const points = [];
    for(let i=0;i<distance;i+=0.1){
        points.push({
            lo: start.lerp(end,0.1*distance*i),
            hi: start.lerp(end,0.1*distance*i),
        })
    }
    world.onTick(()=>{
        points.forEach((e)=>{
            world.searchBox(e).forEach((e)=>{
                if(e.isPlayer){
                    e.hurt(100);
                }
            })
        })
    })
}

以后要放置激光的时候

就在代码区写:

addlaser(激光起始位置,激光结束位置)

就这么简单


回复

上一页1 页 / 共 1下一页
星辰Lolita星辰Lolita

喵=把()()()()()()()玩

点赞1


评论


成熟的强袭编程猫548成熟的强袭编程猫548

沙发

点赞0


评论


云游box3der尖头叉子云游box3der尖头叉子

emotion_编程猫_厉害了

点赞0


评论


星辰Lolita星辰Lolita

函数写错了,应改成:

    const Quat = new Box3Quaternion(0,0,0,1);
    function addlaser(start,end){
        const distance = start.distance(end);
        const laser = world.createEntity({
            mesh: 'mesh/激光.vb',
            meshScale: [0.0625*distance,0.0625,0.0625],
            gravity: false,
            collides: false,
            fixed: true,
            position: start.lerp(end,0.5),
        })
        const d = start.sub(end);
        laser.meshOrientation = Quat.rotateX(Math.atan2(d.y,Math.sqrt(d.x**2+d.z**2))).rotateY(Math.atan2(d.z,d.x));
        const points = [];
        for(let i=0;i<distance;i+=0.1){
            points.push({
                lo: start.lerp(end,0.1*distance*i),
                hi: start.lerp(end,0.1*distance*i),
            })
        }
        world.onTick(()=>{
            points.forEach((e)=>{
                world.searchBox(e).forEach((e)=>{
                    if(e.isPlayer){
                        e.hurt(100);
                    }
                })
            })
        })
    }

点赞1


评论


云游box3der尖头叉子云游box3der尖头叉子

话说模型库里好像没有名叫激光的模型诶

点赞1


评论


YDS尹子YDS尹子

数学基础好强)

几年级啊)

点赞1


评论


QBZ_QBZ_

大佬有兴趣来我图代码吗 https://shequ.codemao.cn/community/379059 https://shequ.codemao.cn/community/386659 https://box3.codemao.cn/e/a44e5180b2e6ac2a1c00

点赞1


评论


YDS尹子YDS尹子

Lolita试试这个

https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=13&ct=1627029906&rver=7.0.6737.0&wp=MBI_SSL&wreply=https%3a%2f%2foutlook.live.com%2fowa%2f%3fnlp%3d1%26RpsCsrfState%3de83cba48-2e1c-b689-d797-9eaa45b3e11f&id=292841&aadredir=1&CBCXT=out&lw=1&fl=dob%2cflname%2cwld&cobrandid=90015

一会儿把我和本尊的邮箱告诉你))

点赞1


评论


AlcalaAlcala

qpOrz

点赞0


评论


化石茄子的铁镐化石茄子的铁镐

Lolita,可不可以帮我在天启大陆解除拉黑,还有回复我之前的建筑师职位,littledream删除了我之前做的建筑

点赞0


评论


YDS尹子YDS尹子

好家伙()

lerp这些函数你是从哪学来的()

点赞2


评论


屑student屑student

Lolita能详细讲解一下lerp函数吗()

点赞0


评论


XiaoLiQAQXiaoLiQAQ

没有用world.raycast吗,倒腾跑酷激光的时候想到world.raycast是不是可以用,然后world.raycast的方向搞不准,searchbox是不是会不精确呢?

点赞1


评论


蓝矮爱乐蓝矮爱乐

az,跑酷斜射激光教程被我挖出来了()

点赞0


评论


没名字pwp没名字pwp

是谁顶上来的a))()

点赞0


评论


治愈绾兮治愈绾兮

精髓找到了:

Quat.rotateX(Math.atan2(d.y,Math.sqrt(d.x**2+d.z**2))).rotateY(Math.atan2(d.z,d.x))

点赞0


评论


银狐残影银狐残影

 

点赞0


评论


彩虹字转换器彩虹字转换器

https://box3.codemao.cn/g/822688

点赞0


评论


彩虹字转换器彩虹字转换器

https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688 https://box3.codemao.cn/g/822688

点赞0


评论


小屑鹿小屑鹿

怎么回事嘛

center_image

点赞0


评论


小树同学小树同学

收藏

点赞0


评论


名字送冷吖O名字送冷吖O

移除函数来啦!

    const Quat = new Box3Quaternion(0,0,0,1);
    function addlaser(start,end){
        const distance = start.distance(end);
        const laser = world.createEntity({
            mesh: 'mesh/激光.vb',
            meshScale: [0.0625*distance,0.0625,0.0625],
            gravity: false,
            collides: false,
            fixed: true,
            position: start.lerp(end,0.5),
        })
        const d = start.sub(end);
        laser.meshOrientation = Quat.rotateX(Math.atan2(d.y,Math.sqrt(d.x**2+d.z**2))).rotateY(Math.atan2(d.z,d.x));
        const points = [];
        for(let i=0;i<distance;i+=0.1){
            points.push({
                lo: start.lerp(end,0.1*distance*i),
                hi: start.lerp(end,0.1*distance*i),
            })
        }
        const tick=world.onTick(()=>{//考虑到移除要把tick关了
            points.forEach((e)=>{
                world.searchBox(e).forEach((e)=>{
                    if(e.isPlayer){
                        e.hurt(100);
                    }
                })
            })
        })
        return{//给函数建立返回值,返回一个对象,里的remove方法就是移除
            remove:()=>{
                tick.cancel();
                laser.destroy();
            }
        }
    }
const laser = addlaser(new Box3Vector3(xxx,xxx,xxx),new Box3Vector3(xxx,xxx,xxx))//xxx表示数字
laser.remove()//移除方法

点赞0


评论