Skip to content

动画示例(RPG 场景)

以下示例都可以直接复制使用。请根据你的模型改 assetclip 名称。

1) 人形玩家(默认模板 + 基础图)

模型 animation/models/default.yml

yml
"rpg:player":
  asset: "builtin/default"
  collider:
    width: 0.6
    height: 1.8

Graph animation/graphs/default.yml

yml
"rpg:player":
  layers:
    - name: base
      weight: 1.0
      blend: OVERRIDE
      default: idle
    - name: upper
      weight: 1.0
      blend: ADDITIVE
      default: idle

  states:
    - name: idle
      layer: base
      clip: idle
      speed: 1.0
      loop: loop
      rootMotion: true

    - name: run
      layer: base
      clip: run
      speed: 1.0
      loop: loop
      rootMotion: true

    - name: attack
      layer: upper
      clip: attack
      speed: 1.0
      loop: once
      rootMotion: false

  transitions:
    - from: idle
      to: run
      condition: "v.speed > 0.2"
      blendTime: 0.2

    - from: run
      to: idle
      condition: "v.speed <= 0.2"
      blendTime: 0.2

    - from: run
      to: attack
      condition: "v.skill_attack == 1"
      blendTime: 0.1

  clips:
    idle:
      length: 1.0
      rootMotion:
        mode: disabled

    run:
      length: 1.0
      rootMotion:
        mode: velocity
        velocity: [0, 0, 1.2]
        yawSpeed: 0

    attack:
      length: 0.6
      rootMotion:
        mode: disabled

绑定 animation/bindings/default.yml

yml
rpg_player:
  selector: "minecraft:player"
  model: "rpg:player"
  graph: "rpg:player"
  vars:
    speed: 0.0
    skill_attack: 0
  flags:
    applyRootMotion: true
    footIk: true
  priority: 0

2) Boss 冲锋(曲线 RootMotion)

Graph animation/graphs/default.yml

yml
"rpg:boss":
  layers:
    - name: base
      weight: 1.0
      blend: OVERRIDE
      default: idle

  states:
    - name: idle
      layer: base
      clip: idle
      speed: 1.0
      loop: loop
      rootMotion: true

    - name: charge
      layer: base
      clip: boss_charge
      speed: 1.0
      loop: once
      rootMotion: true

  transitions:
    - from: idle
      to: charge
      condition: "v.phase == 2"
      blendTime: 0.1

  clips:
    idle:
      length: 1.0
      rootMotion:
        mode: disabled

    boss_charge:
      length: 0.8
      rootMotion:
        mode: curve
        curve:
          - {t: 0.0, pos: [0, 0, 0]}
          - {t: 0.2, pos: [0, 0, 8]}
          - {t: 0.6, pos: [0, 0, 20]}
          - {t: 0.8, pos: [0, 0, 24]}
        yaw:
          - {t: 0.0, yaw: 0}
          - {t: 0.8, yaw: 15}

绑定 animation/bindings/default.yml

yml
rpg_boss:
  selector: "minecraft:zombie[name=Boss*]"
  model: "example:boss"
  graph: "rpg:boss"
  vars:
    phase: 0
  flags:
    applyRootMotion: true
  priority: 100

3) 武器/披风挂载(Wardrobe)

Wardrobe animation/wardrobe/default.yml

yml
"rpg:knight_wardrobe":
  slots:
    - slot: WEAPON
      model: "rpg:weapon_sword"
      attach: "bone:hand_r"
  overrides:
    hideEquipment: true

模型定义 animation/models/default.yml

yml
"rpg:weapon_sword":
  asset: "weapons/sword_a"

绑定 animation/bindings/default.yml

yml
rpg_knight:
  selector: "minecraft:player"
  model: "rpg:player"
  graph: "rpg:player"
  wardrobe: "rpg:knight_wardrobe"
  vars:
    speed: 0.0
  flags:
    applyRootMotion: true
    footIk: true
  priority: 0

4) IK / 脚步修正(完整示例)

yml
vars:
  ik:
    enabled: true
    groundedOnly: true
    rootBones: ["root", "hips"]
    leftFoot: "foot_l"
    rightFoot: "foot_r"
    contactHeight: 1.2
    contactThreshold: 0.25
    lockStrength: 1.0
    lockFadeIn: 0.12
    lockFadeOut: 0.18
    twoBoneIk: true
    twoBoneIkWeight: 1.0
    lod:
      near: 32
      mid: 64
      far: 96
    speedSync:
      enabled: true
      target: 4.3
      min: 0.6
      max: 1.4
      layer: "base"
flags:
  footIk: true

这些示例均可直接使用,按实际模型与动画名调整即可。