用户:
全能代码师查看: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
这段代码的弓箭位置和伤害效果会不理想,因为撞到玩家会有延迟,所以会有奇怪的击退和不精准的命中,而且y坐标+1会使射不到近距离目标,因使用碰撞过滤加上碰撞箱检测搭配高速循环对弓箭的伤害进行判断,这样效果会更好
点赞0
评论
幕川北事情是这样的:
这个男人叫小明他还是一如既往的打着代码

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

是个聪明人都会发现一个问题:
nnd!!!!为神喵弹从他的身体穿了过去!
people1:人物开了碰撞吗
我:神岛默认人物开启碰撞
people2:速度是不是太快了
我:速度调了speed=1还不慢吗。。。。。
people3:子弹开了碰撞吗?
我:我开了子弹碰撞
请各位大佬帮助我吧!!!!!!
呜呜TwT我太难了啊啊啊


点赞1
评论