Mirroring an animation

Hi!
Is it possible to make a perfect copy of an animation with some curves reversed? I.E. if I’m having a sword that slashes to the right, could I somehow mirror a copy of this animation to have the exact same movement, but to the left?

Thanks for your help.

2 Likes

A simple google search reveals the answer you require.

Then perhaps I’m searching for the wrong thing, because I’ve been at it the whole day, and I’m unable to find anything solid.

Wait - might need to clarify
Are you looking to keep the animation you have but change the sword swing right to sword swing left. Still keeping the same animation - in the same hand?
OR
Mirror the entire animation so the right sword swing (with the right hand) is mirrored and the resulting animation is a left sword swing (with the left hand).

If #1 - afaik - no that is not doable in Unity. It’s a simple thing in 3D that would result in a new animation, but not within Unity.
If #2 - yes - a very simple process that is revealed in the top 5 google search results.

There are no hands, it’s a floating sword, in 2D. I’m aware that you can easily mirror humanoid-based animations in 3D, but this is not the case. Perhaps posting a picture will clear things up. Here goes:

I want the little floating sword to have a set of left-side and right-side animations (for when the character turns around). The sword is a child object of the player cube, has it’s own separate animator. The question is whether I’ll be able to somehow copy and mirror the swords animations along player’s Y axis (since I already have all the right-side animations), or would I have to manually set all the “lefties” up from scratch?

Thanks.

Figured it out.
Turns out, when you flip the parent object (X axis * -1), the child object AND it’s animations get flipped, too. I was so convinced that was too simple to work, that I didn’t even try it in the first place. Silly me.

6 Likes

Glad you solved and updated. Great for sharing. :wink:

gotta love the just google it when they become top result smh

19 Likes

Especially when this was now the top google result for me

19 Likes

Yeah same. Wouldn’t it have been nice if someone could have just answered the question instead of coming off as condescending and arrogant? Wishful thinking, I know

22 Likes

Wow! So that is how to do it and it flips the animations too? Interesting.

1 Like

This is the first response on Google now, are you proud of yourself?

4 Likes

Judgeking, Yeah, when I ask a question, especially on Stackoverflow, I almost always get condescending, arrogant person like him responding to me. I don’t know why there are so many of them out there. On Stackoverflow, it’s even worse than Unity because they downvote you too, which lowers your score. It’s not fair when I’m asking a genuine question that I was unable to find an answer to by many google searches sigh

6 Likes

It may be already too late here, but i will share how i mirrored or i should say how Chat GPT did it.

SPOILER!
I used localscale to mirror.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerAnimation : MonoBehaviour
{
    private Animator anim;

    private PlayerAnimation playerAnim;


    private void Awake()
    {
        anim = GetComponent<Animator>();
        playerAnim = GetComponent<PlayerAnimation>();
    }


    public void Play_WalkAnimation(int walk)
    {
        anim.SetInteger(TagManager.WALK_ANIMATION_PARAMETER, walk);
    }

    public void PLay_JumpAnimation(bool jump)
    {
        anim.SetBool(TagManager.JUMP_ANIMATION_PARAMETER, jump);
    }




    // THIS PART HERE   |
    //                                 |
    //                                V
    public void SetFacingDirection(int facingDir)
    {
        if (facingDir > 0)
        {
            // Code to execute when facingDir is greater than 0
            // For example:
            playerAnim.transform.localScale = new Vector3(1f, 1f, 1f); // Set the local scale of the player to (1, 1, 1) to maintain the original orientation
        }
        else if (facingDir < 0)
        {
            // Code to execute when facingDir is less than 0
            // For example:
            playerAnim.transform.localScale = new Vector3(1f, 1f, -1f); // Set the local scale of the player to (-1, 1, 1) to mirror the player horizontally
        }
    }

}

Here is a way to mirror a Humanoid animation clip, using just the Inspector, no code needed:

Answering with the top 5 google results, knowing that they change overtime, it’s not just arrogant, it’s absurd.

2 Likes