猫史档案馆


新型激光教程(可移动&可斜向)

用户:小屑鹿小屑鹿查看:0 回复:5 评论:0 创建时间:2023-05-13T11:37:37


灵感来源于tiger的弹幕游戏

激光代码来源于Lolita的斜射激光

原理:点到直线距离公式

代码比较粗糙(主要是把测试的弹幕发了出来(还没改函数(可以看看思路:

const Quat = new Box3Quaternion(0, 0, 0, 1);
const posA = world.querySelector('#A').position
const posB = world.querySelector('#B').position
const mid = new Box3Vector3((posA.x - posB.x) * 0.5, 16.5, (posA.z - posB.z) * 0.5)
const realA = new Box3Vector3(posA.x - mid.x, 16.5, posA.z - mid.z)
const realB = new Box3Vector3(posB.x - mid.x, 16.5, posB.z - mid.z)
const k =(realA.z - realB.z) / (realA.x - realB.x)
const b = realA.z - realA.x * k
world.onTick(({}) => {
    world.querySelectorAll('player').forEach((e) => {
        if (Math.abs(e.position.x * k - e.position.z + b) / Math.sqrt(1 + k ^ 2) <= 0.3) {
            e.enableDamage = true
            e.hurt(1)
        }
    })
})
function addlaser(start, end) {
    const distance = start.distance(end);
    const laser = world.createEntity({
        mesh: 'mesh/line.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));
}
addlaser(posA,posB)


回复

上一页1 页 / 共 1下一页
box3的果敢的超能鸭viwXbox3的果敢的超能鸭viwX

怎么没人抢沙发呢?我抢了()emotion_星能猫_ye

点赞1


评论


yee剑走天下yee剑走天下

收藏

点赞0


评论


神奇代码岛func王清林神奇代码岛func王清林

  

 

 

点赞0


评论


天冷记得盖被子天冷记得盖被子

emotion_太开心

点赞0


评论


小屑鹿小屑鹿

其实这玩意儿原本是当音游判定线使的()

点赞0


评论