用户:
星辰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(激光起始位置,激光结束位置)
就这么简单
星辰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
评论
QBZ_大佬有兴趣来我图代码吗 https://shequ.codemao.cn/community/379059 https://shequ.codemao.cn/community/386659 https://box3.codemao.cn/e/a44e5180b2e6ac2a1c00
点赞1
评论
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
评论
治愈绾兮精髓找到了:
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
评论