轨道炮攻略

1.13轨道炮以及追踪弹道修正系统

不过轨道炮的子弹只是来卖萌的而已,呈现的核心部分在于实装在其之上的 追踪弹道修正系统

此追踪并非百发百中的必中,而是根据追踪目标的位置 对自身的弹道进行偏移修正,

通俗的说就是子弹的前进方向随着目标移动慢慢偏向目标位置,可实现更加真实的特效。

此模块可自定义 追踪的目标点 ——追踪目标的头部或脚部,也可自定义 追踪时的偏移速度 和 追踪角度范围

效果图:

追踪范围内——追踪成功效果

我的世界制作1.13轨道炮以及追踪弹道修正系统攻略
目标超出追踪范围——追踪失败效果

我的世界制作1.13轨道炮以及追踪弹道修正系统攻略
那么进入讲解环节

本次讲解涉及1.13的指令,如果对指令不了解的同学请自行转到指令讲解贴内学习

重点讲解追踪部分的运算,子弹的移动效果实现不做讲解。

追踪模块代码:

#子弹追踪曲线修正

#Usage: execute as @e[tag=bullet,...] at @s run function pack:(...)/bullet_tracking

#Scoreboard

scoreboard objectives add Bullet_RotX dummy

scoreboard objectives add Bullet_RotY dummy

scoreboard objectives add ToTarget_RotX dummy

scoreboard objectives add ToTarget_RotY dummy

scoreboard objectives add Math dummy

#Get_Data

execute store result score @s Bullet_RotX run data get entity @s Rotation[0] 1000000

execute store result score @s Bullet_RotY run data get entity @s Rotation[1] 1000000

#Get_ToTarget_Data

execute as @s at @s anchored feet run tp @s ~ ~ ~ facing entity @e[type=!player,tag=!bullet,distance=..20,limit=1] feet

#瞄准位置(eyes/feet)

execute store result score @s ToTarget_RotX run data get entity @s Rotation[0] 1000000

execute store result score @s ToTarget_RotY run data get entity @s Rotation[1] 1000000

execute store result entity @s Rotation[0] float 0.000001 run scoreboard players get @s Bullet_RotX

execute store result entity @s Rotation[1] float 0.000001 run scoreboard players get @s Bullet_RotY

#-----水平偏移-----

#Offset_Calculation

scoreboard players operation @s Math = @s ToTarget_RotX

scoreboard players operation @s Math -= @s Bullet_RotX

# 偏移探测范围↓ 偏移角度参数↓

execute as @s at @s if score @s Math matches -90000000..0 run tp @s ~ ~ ~ ~-2 ~

execute as @s at @s if score @s Math matches 0..90000000 run tp @s ~ ~ ~ ~2 ~

#-----竖直偏移-----

#Offset_Calculation

scoreboard players operation @s Math = @s ToTarget_RotY

scoreboard players operation @s Math -= @s Bullet_RotY

# 偏移探测范围↓ 偏移角度参数↓

execute as @s at @s if score @s Math matches -90000000..0 run tp @s ~ ~ ~ ~ ~-2

execute as @s at @s if score @s Math matches 0..90000000 run tp @s ~ ~ ~ ~ ~2

复制代码

此代码附件内同样也有,需要的同学可自行搬用

核心思路:

1.13指令系统中,记分板能够读取实体的NBT数据,并存储为整形(integer),因此可以将实体的Rotation存储到记分板内。

但实际的情况中,实体的Rotation是浮点数(float),为了使追踪系统尽量精确,需要将存储到记分板的 小数 数值进行放大,

把小数的数值转换成整数存储进记分板,在数据回调至实体NBT时再缩小存入。

简单介绍记分板的作用:

Bullet_RotX、Bullet_RotY —— 分别存储 子弹实体 实时的Rotation X、Y的数值

ToTarget_RotX、ToTarget_RotY —— 分别存储 子弹实体 基于面向追踪目标状态 的实时 Rotation X、Y 的数值

Math —— 对以上四个记分板数值的运算结果存储

每部分算法分析:

Get_Data —— 将子弹的Rotation放大1000000倍,存入Bullet_RotX、Bullet_RotY记分板中

Get_ToTarget_Data —— 以子弹面向目标时的Rotation放大1000000倍,存入ToTarget_RotX、ToTarget_RotY记分板中

再将子弹原先的朝向数据,通过Bullet_RotX、Bullet_RotY的值 缩小1000000倍 赋值回去

*注意,这里可以修改追踪目标的追踪位点——头部或脚部

接下来的运算就不必多说,将ToTarget_Rot 数据减去 Bullet_Rot ,对应结果存入Math记分板中 ,对Math的值进行判定,执行对应的朝向tp旋转

*注:在这里可以同时调整旋转的程度 ,以及Math的范围判定调整(甚至可以..0 , 0..这么玩)。

当然,这个追踪系统只包含水平和竖直方向上的追踪,没有实现任意弧度的追踪,

但可在此基础上做 朝向分段判定拓展,实现不同偏移加速度。

发表评论

您必须 登录 才能发表留言!