动画中的特效
动画中的特效
有时在动画中使用粒子或音效比在动画控制器中使用要简单得多。 动画中可以包含以下特效:
- 粒子效果
- 音效
粒子效果
Minecraft的粒子效果可用于实体动画中。例如,幻影有一个持续释放minecraft:phantom_trail粒子的动画。让我们尝试为实体的攻击动画添加粒子效果。
RP/entity/my_entity.json
json
"particle_effects": {
"flames": "minecraft:mobflame_emitter"
}这里我们为要使用的粒子定义了一个简称。
注意!
并非所有粒子都能正常使用。如果遇到问题,请尝试更换其他粒子。例如使用这个。 另外请注意,某些粒子会持续发射。
音效
若要使用音效,同样需要先进行定义。 你可以在ZapSplat获取音效资源。
RP/entity/my_entity.json
json
"sound_effects": {
"meow": "mob.cat.meow"
}注意!
并非所有音效都能正常使用。如果遇到问题,请尝试更换其他音效。例如使用这个。
为动画添加特效
你可以通过代码或Blockbench为动画添加粒子或音效。
通过代码
需要在动画中添加以下内容:
RP/animations/my_animation.json#my.animation
json
"particle_effects": {
"0.0": {
"effect": "flames",
"locator": "" //需要在模型中添加定位器
}
}RP/animations/my_animation.json#my.animation
json
"sound_effects": {
"0.0": {
"effect": "meow"
}
}可以同时调用多个粒子效果:
json
"particle_effects": {
"0.0": [
{
"effect": "particle_1",
"locator": "locator_1"
},
{
"effect": "particle_2",
"locator": "locator_2"
}
]
}示例
RP/animations/my_animation.json
json
{
"format_version" : "1.8.0",
"animations" : {
"animation.sheep.grazing" : {
"animation_length" : 2.0,
"loop" : true,
"particle_effects": {
"0.0": {
"effect": "flames",
"locator": "body"
}
},
"sound_effects": {
"0.0": {
"effect": "meow"
}
},
"bones" : {
"head" : {
"position" : {
"0" : [ 0.0, 0.0, 0.0 ],
"0.2" : [ 0.0, -9.0, 0.0 ],
"1.8" : [ 0.0, -9.0, 0.0 ],
"2" : [ 0.0, 0.0, 0.0 ]
},
"rotation" : {
"0.2" : {
"post" : [ "180.0 * (0.2 + 0.07 * math.sin(q.key_frame_lerp_time * 1644.39))", 0.0, 0.0 ],
"pre" : [ 36.0, 0.0, 0.0 ]
},
"1.8" : {
"post" : [ 36.0, 0.0, 0.0 ],
"pre" : [ "180.0 * (0.2 + 0.07 * math.sin(q.key_frame_lerp_time * 1644.39))", 0.0, 0.0 ]
}
}
}
}
}
}
}通过Blockbench
首先为粒子添加定位器。进入"编辑"部分,选择一个组,右键点击并选择"添加定位器":

重命名并移动到所需位置。
然后进入"动画"部分,选择动画并点击魔法棒图标:

点击"+"打开菜单并指定数据:

音效也可以用同样的方式附加到动画上。
保存动画后启动游戏即可!

注意!
当前版本(1.21.1)中,可附着实体的定位器存在bug。
屏幕外更新
可以在实体资源包脚本中将"should_update_bones_and_effects_offscreen"设为true,使粒子和音效在屏幕外也能持续更新。默认情况下,当实体不在显示范围内时,这些效果都会停止播放。
RP/entity/my_entity.json#description
json
"scripts": {
"should_update_bones_and_effects_offscreen": true
}