我需要通过 SpineAnimationState.add_animation() 在0号轨道上不断添加新动画,并且我需要新动画能以曲线插值方式来过渡旧动画

我知道可以用 SpineTrackEntry.set_mix_duration() 来设置过渡,但这个是线性插值,效果不尽人意

我也知道可以用 SpineTrackEntry.set_alpha() 使用自定义值来实现曲线插值,但每次使用 SpineAnimationState.add_animation() 时,动画都会跳转到默认姿势开始过渡,而不是从现有状态继续过渡

我该怎么让动画从现有的状态继续过渡?

    Related Discussions
    ...

    在 Godot 中使用 SpineAnimationState.add_animation() 添加新动画时,如果希望实现从现有状态的曲线插值过渡,可以考虑以下方法:

    1. 使用自定义插值函数:虽然 SpineTrackEntry.set_mix_duration() 默认是线性插值,但你可以通过在每帧更新中手动调整 SpineTrackEntry 的 alpha 值来实现自定义的插值曲线。你可以在每帧的 _process(delta) 函数中计算出一个自定义的插值值,并将其应用到 TrackEntry 的 alpha 属性上。

    2. 保持动画状态:为了避免动画从默认姿势开始过渡,你可以在添加新动画之前,先将当前动画的状态保存下来。然后在新动画开始时,手动将保存的状态应用到新动画的起始状态上。这需要对骨骼的当前变换进行手动管理。

    3. 使用空动画:在添加新动画之前,可以先添加一个空动画(empty animation),并设置一个较短的混合时间。这样可以在新动画开始之前,平滑地过渡到一个中间状态。

    以下是一个简单的示例代码,展示如何在每帧更新中手动调整 alpha 值:

    extends SpineSprite
    
    var current_alpha = 0.0
    var target_alpha = 1.0
    var alpha_speed = 0.1
    
    func _ready():
        var animation_state = get_animation_state()
        animation_state.set_animation("idle", true, 0)
        animation_state.add_animation("walk", 0.5, true, 0)
    
    func _process(delta):
        var track_entry = animation_state.get_current(0)
        if track_entry:
            current_alpha = lerp(current_alpha, target_alpha, alpha_speed * delta)
            track_entry.alpha = current_alpha

    通过这种方式,你可以在每帧中动态调整 alpha 值,实现更复杂的插值效果。

      Spinebot
      我具体该怎么“将当前动画的状态保存下来”,“将保存的状态应用到新动画”呢?

      kBlankii There may be an issue in your code that causes the animation to briefly revert to the setup pose. Check if you are calling a method like setToSetupPose(), which resets the skeleton to the setup pose.

      Alternatively, the issue might be due to elements that cannot be blended. For example, toggling an attachment's visibility or enabling/disabling a constraint cannot be blended, so they switch states instantly.

      In any case, sharing the code that handles your animations will help us better understand the issue and provide more accurate advice.