话不多说,直接上图.
单体射击效果
贯穿射击效果
|
效果实现基于便利的工具人区域效果云(area_effect_cloud,以下简称AEC).
设计思路:
1.设置两个单位的AEC,分别生成在玩家位置(A)与目标位置(B).
2.让A去找B玩.咳咳,对A高频执行TP,目的地为B.
3.A与B交汇后,或是命中实体后,判定完成一次射击.
原理不复杂,但是遇到了不少预想外的情况,着实费了一番功夫.
由于不知名原因我发代码的时候总是被吞的只剩一行,这次就直接折叠不加代码格式了.
下面上代码.
预设计分板
scoreboard objectives add shoot minecraft.used:minecraft.carrot_on_a_stick
scoreboard objectives add time dummy
scoreboard objectives add cd dummy
scoreboard players set @p cd 20
设置AEC
execute as @e[tag=!cd] at @s if score @s shoot matches 1 run summon minecraft:area_effect_cloud ^ ^1 ^15 {Duration:15,Tags:["b"]}
execute as @e[tag=!cd] at @s if score @s shoot matches 1 run summon minecraft:area_effect_cloud ~ ~1 ~ {Duration:15,Tags:["a"]}
execute as @e[tag=a] at @s run tp @s ^ ^ ^ facing entity @e[tag=b,sort=nearest,limit=1]
execute as @e[tag=!cd] at @s if score @s shoot matches 1 run tag @s add cd
AEC的移动与轨迹可视化
execute as @e[tag=a] at @s run tp @s ^ ^ ^1 facing entity @e[tag=b,sort=nearest,limit=1]
execute as @e[tag=a] at @s run particle minecraft:firework ~ ~ ~ 0 0 0 0 1 normal
射速限制
execute as @e[tag=cd] at @s run scoreboard players add @s time 1
execute as @e[tag=cd] at @s if score @s time >= score cd run tag @s remove cd
execute as @e[tag=!cd] at @s run scoreboard players reset @s time
execute as @e[tag=!cd] at @s run scoreboard players reset @s shoot
单体攻击
execute as @e[tag=a] at @s positioned ^ ^ ^ run tag @e[type=wolf,limit=1,sort=nearest,distance=..1] add damage
execute as @e[tag=damage] at @s run kill @e[tag=a,limit=1,sort=nearest,distance=..1]
execute as @e[tag=damage] at @s run effect give @s instant_damage 1 2 true
execute as @e[tag=damage] at @s run tag @s remove damage
贯穿攻击
execute as @e[tag=a] at @s positioned ^ ^ ^ run effect give @e[type=!player,distance=..1] instant_damage 1 2 true
|
一个代码段就是一套连锁,将第一个设置成高频即可实现效果.
除去不需占用方块的计分板预设,一共需要用到14(单体攻击)或11(贯穿攻击)个命令方块
下面为不怎么熟悉指令的人补上话痨版,便于自行调整参数
预设计分板
scoreboard objectives add shoot minecraft.used:minecraft.carrot_on_a_stick
设置胡萝卜钓竿为触发器,carrot_on_a_stick可以改为你想要做触发器的物品
scoreboard objectives add time dummy
设置计时器
scoreboard objectives add cd dummy
设置冷却时间
scoreboard players set @p cd 20
设置冷却时间为20
设置AEC
execute as @e[tag=!cd] at @s
当射击动作未处于冷却状态时
if score @s shoot matches 1
如果执行了射击动作
run summon minecraft:area_effect_cloud ^ ^1 ^15 {Duration:15,Tags:["b"]}
设置AEC[B]
此处 ^ ^1 ^15 中的数字15影响射程,数字越大射程越远
Duration:15则是持续时间,建议与射程的数字同步
execute as @e[tag=!cd] at @s
if score @s shoot matches 1
run summon minecraft:area_effect_cloud ~ ~1 ~ {Duration:15,Tags:["a"]}
设置AEC[A]
Duration需和B点同步
execute as @e[tag=a] at @s
run tp @s ^ ^ ^ facing entity @e[tag=b,sort=nearest,limit=1]
调整AEC[A]的朝向,使其面向AEC[B]
如果不加这一条,AEC[A]的第一次移动会朝实体生成时的默认朝向(南)进行
execute as @e[tag=!cd] at @s
当射击动作未处于冷却状态时
if score @s shoot matches 1
如果执行了射击动作
run tag @s add cd
添加cd标签,让玩家进入射击冷却状态
子弹的移动与轨迹
execute as @e[tag=a] at @s
run tp @s ^ ^ ^1 facing entity @e[tag=b,sort=nearest,limit=1]
让AEC[A]朝着AEC[B]的方向移动
此处 ^ ^ ^1 中的数字1影响弹速,虽然能够调整,但不建议调整
因为弹速对射击的实际效果影响巨大,需要调整许多的数据,十分麻烦
execute as @e[tag=a] at @s
run particle minecraft:firework ~ ~ ~ 0 0 0 0 1 normal
为AEC[A]添加粒子效果,使子弹轨迹可视化
射击冷却
execute as @e[tag=cd] at @s
run scoreboard players add @s time 1
当玩家处于射击冷却状态时,计时器运作
execute as @e[tag=cd] at @s
if score @s time >= score cd
run tag @s remove cd
计时器运作时长大于冷却时间后,移除玩家的冷却标签,退出冷却状态
execute as @e[tag=!cd] at @s
run scoreboard players reset @s time
当玩家处于非冷却状态时,计时器清零
execute as @e[tag=!cd] at @s
run scoreboard players reset @s shoot
当玩家处于非冷却状态时,射击动作值清零
清零后,逻辑回到最上层,一次射击效果便完整的体现出来了
单体攻击
攻击判定上,这里只是简略的给出了两种,各位可以发挥自己的想象力实现各种各样的攻击效果,如爆破设计,buff子弹等等
execute as @e[tag=a] at @s positioned ^ ^ ^
run tag @e[type=wolf,limit=1,sort=nearest,distance=..1] add damage
选取距离子弹AEC[A]最近并且距离小于1的实体,添加伤害判定标签damage
举例中使用了type=wolf使目标限定为狼,这里可以随意修改
使用team操作来编队后再选择非友军也是可行的,只是实现组队对战时有很多细节需要修改
万万不能不添加选择器,不然生存模式一枪射出来直接判定在自己胸口distance后的数字会影响子弹的碰撞范围,要实现精确打击的话可以把数字再小点,想玩轨道炮就调大点
execute as @e[tag=damage] at @s
run kill @e[tag=a,limit=1,sort=nearest,distance=..1]
反向选取被添加了伤害判定的实体,检测距它最近的子弹AEC[A]并移除它
execute as @e[tag=damage] at @s
run effect give @s instant_damage 1 2 true
执行伤害
这里就是发挥想象力的地方了
瞬移枪了解一下?浮空枪了解一下?
execute as @e[tag=damage] at @s
run tag @s remove damage
清除伤害判定标签,避免实体没死亡的时候无限扣血
贯穿攻击
execute as @e[tag=a] at @s positioned ^ ^ ^
run effect give @e[type=!player,distance=..1] instant_damage 1 2 true
对没错就是这么暴力,单体攻击需要截断子弹并移除,贯穿攻击就不需要考虑这么多了
到射程极限前途经的所有满足命中判定的生物都会受到攻击判定
详见效果图2,子弹过处寸草不生.
|
呼,该摆上去的都摆完了,接下来说一些小细节.
1.没有对墙体进行任何处理,所以这个子弹是能穿墙的
思路写出来了,在子弹移动的时候判断它所处的位置是不是空气,如果不是,移除
就当做课后题给大家吧.才不是我懒得做.
2.上面的话痨版有提到,多人游戏的时候需要调整很多内容
理论上来讲每个玩家都需要一套命令方块组,AEC与Damage等等标签的命名都需要独立才不会互相冲突.
想知道冲突的时候会怎么样,请把CD设置为0,然后朝不同方向射击,观察弹道.
3.这种攻击方式不吃仇恨,这点已经拿狼和僵尸猪人测试过了
所以就算没有小伙伴我也不难推断这个东西是没有击杀归属的
这也是要做多人对战的时候需要调整的东西之一
4.粒子效果不是我的专长,如果有玩粒子的大佬能给出更好看的轨迹效果那就再好不过了,欢迎大佬晒粒子
5.如果有使用这个思路做出什么好玩的东西,请务必通知我去围观
好了,就是这样,收工.
|