用户:
星辰Lolita查看:912 回复: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(激光起始位置,激光结束位置)
就这么简单
星辰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
评论
能不能做一个移除函数啊,移除原有的激光
我想这得再加好多代码
没有必要做移除吧?
不用 很简单的 用global.entitys加一个全局数组 然后把创建的实体放到entitys里面 有必要的时候就索引+移除实体
说句实话 顶多加不到10行
怎么用啊,有实例吗
YDS尹子数学基础好强)
几年级啊)
点赞1
评论
6(
!!!!!
三角函数你也是自学的??
在线?
没学
只是会用
在啊https://box3.codemao.cn/e/a44e5180b2e6ac2a1c00
真好)我在六年级的时候还在琢磨着怎么造球
邮箱能用了吗。?
不能
QBZ_大佬有兴趣来我图代码吗 https://shequ.codemao.cn/community/379059 https://shequ.codemao.cn/community/386659 https://box3.codemao.cn/e/a44e5180b2e6ac2a1c00
点赞1
评论
你在线??
(Omega的路上怎么全是跑车)(我帮你换了一个我自己做的轿车))
其实我早就想换了(都换成你的
我omega进不去了,人满了
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
评论
XiaoLiQAQ没有用world.raycast吗,倒腾跑酷激光的时候想到world.raycast是不是可以用,然后world.raycast的方向搞不准,searchbox是不是会不精确呢?
点赞1
评论
是想来学world.raycast的
注意发帖日期()
起床试炼lz自瞄用的就是raycast()挺简单的()
result = world.raycast(起点,方向,更多参数(可以不填))
但如果用raycast检测模型的时候最先检测到的是激光的模型
主要的是方向搞不明白
确实,而且你这个searchbox跟raycast差不多了已经
治愈绾兮精髓找到了:
Quat.rotateX(Math.atan2(d.y,Math.sqrt(d.x**2+d.z**2))).rotateY(Math.atan2(d.z,d.x))点赞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
评论
名字送冷吖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
评论