用户:
山衫惠子查看:2 回复:6 评论:2 创建时间:2020-01-27T22:08:43
加个点赞与关注,找个清泉不迷路。请复制以下代码:
//一个简单的射击PvP
world.onPlayerJoin(({ entity }) => {
entity.enableDamage = true;
entity.player.onPress(({ button, raycast:{ hitEntity, direction } }) => {
if (button !== 'action0' || !hitEntity) {
return;
}
hitEntity.velocity.x += direction.x;
hitEntity.velocity.y += 0.5;
hitEntity.velocity.z += direction.z;
hitEntity.hurt(20 * Math.random() + 5, {
attacker: entity,
});
});
});
world.onDie(({ entity, attacker }) => {
if (attacker) {
world.say(attacker.player.name + '打败了' + entity.player.name)
}
entity.player.forceRespawn();
});
然后添加一个3D模型,运行程序,点击3D模型,你会发现,3D模型飞了!
//在判断那里加一个isPlayer就行了
world.onPlayerJoin(({ entity }) => {
entity.enableDamage = true;
entity.player.onPress(({ button, raycast:{ hitEntity, direction } }) => {
if (button !== 'action0' || !hitEntity||!hitEntity.isPlayer) {
return;
}
hitEntity.velocity.x += direction.x;
hitEntity.velocity.y += 0.5;
hitEntity.velocity.z += direction.z;
hitEntity.hurt(20 * Math.random() + 5, {
attacker: entity,
});
});
});
world.onDie(({ entity, attacker }) => {
if (attacker) {
world.say(attacker.player.name + '打败了' + entity.player.name)
}
entity.player.forceRespawn();
});
点赞0
评论