• RuntimesUnity
  • How to fix rotation between track animation and emptyAnimation?

I want to mix 2 tracks animation, and I know it needs to add empty animation.

But there is an overall rotation of the animations, so when I add the empth animation, it willl trigger a brief, instantaneous rotation error. Is there a way to fix the rotation difference within code, instead of recreate the spine file?

  • Levin ha risposto a questo messaggio
    Related Discussions
    ...

    To address the rotation issue when mixing animations with an empty animation, you can use the resetRotationDirections method on the TrackEntry. This method helps to reset the rotation directions, which can prevent the brief rotation error you are experiencing. Additionally, ensure that the shortestRotation property is set appropriately to handle the rotation direction during mixing.

    Here's how you can modify your code to include these adjustments:

    public void StartPlaySpecialAni(AnimationReferenceAsset aimFirst, AnimationReferenceAsset aimSecond, bool aimLoop = false, bool aim2Loop = true) {
        TrackEntry shootTrack = AnimationState.SetAnimation(1, aimFirst, aimLoop);
        shootTrack.MixAttachmentThreshold = 1f;
        shootTrack.SetMixDuration(0f, 0f);
        AnimationState.AddEmptyAnimation(1, 1f, aimFirst.Animation.Duration);
        Debug.Log(shootTrack);
    
        TrackEntry aimTrack = AnimationState.SetEmptyAnimation(2, 0.1f);
        aimTrack.resetRotationDirections(); // Reset rotation directions
        aimTrack.shortestRotation = true; // Use shortest rotation direction
        AnimationState.AddAnimation(2, aimSecond, aim2Loop, aimFirst.Animation.Duration);
        aimTrack.MixAttachmentThreshold = 1f;
        aimTrack.SetMixDuration(0f, 0f);
        Debug.Log(aimTrack);
    
        AnimationState.AddEmptyAnimation(2, 0.1f, aimSecond.Animation.Duration);
    }

    By resetting the rotation directions and ensuring the shortest rotation path is used, you can mitigate the rotation discrepancies when transitioning between animations.

    Levin public void StartPlaySpecialAni(AnimationReferenceAsset aimFirst,AnimationReferenceAsset aimSecond,bool aimLoop = false,bool aim2Loop = true) {
    TrackEntry shootTrack = AnimationState.SetAnimation(1, aimFirst, aimLoop);
    shootTrack.MixAttachmentThreshold = 1f;
    shootTrack.SetMixDuration(0f, 0f);
    AnimationState.AddEmptyAnimation(1, 1f, aimFirst.Animation.Duration);
    Debug.Log(shootTrack);

            TrackEntry aimTrack = AnimationState.SetEmptyAnimation(2, 0.1f);
            AnimationState.AddAnimation(2, aimSecond, aim2Loop,aimFirst.Animation.Duration);
            aimTrack.MixAttachmentThreshold = 1f;
            aimTrack.SetMixDuration(0f, 0f);
            Debug.Log(aimTrack);
            {
                AnimationState.AddEmptyAnimation(2, 0.1f, aimSecond.Animation.Duration);
            }
        }`

    `

    @Levin The above message contains only a quote of the code posted by Spinebot. Did you accidentally delete the actual question line from your posting?