Search Unity

Mirroring an animation

Discussion in 'Animation' started by FestusVG, Jun 3, 2017.

  1. FestusVG

    FestusVG

    Joined:
    May 11, 2017
    Posts:
    9
    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.
     
    Joshsrno and Alpha_Centauri2 like this.
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    A simple google search reveals the answer you require.
     
  3. FestusVG

    FestusVG

    Joined:
    May 11, 2017
    Posts:
    9
    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.
     
  4. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    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.
     
  5. FestusVG

    FestusVG

    Joined:
    May 11, 2017
    Posts:
    9
    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.
     
  6. FestusVG

    FestusVG

    Joined:
    May 11, 2017
    Posts:
    9
    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.
     
  7. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Glad you solved and updated. Great for sharing. ;)
     
  8. Macqueen

    Macqueen

    Joined:
    Aug 29, 2013
    Posts:
    1
    gotta love the just google it when they become top result smh
     
  9. hyyrylainentommi

    hyyrylainentommi

    Joined:
    Nov 16, 2020
    Posts:
    1
    Especially when this was now the top google result for me
     
  10. Judgeking

    Judgeking

    Joined:
    Apr 15, 2017
    Posts:
    17
    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
     
  11. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    Wow! So that is how to do it and it flips the animations too? Interesting.
     
    ijela likes this.
  12. LeakedDave

    LeakedDave

    Joined:
    Aug 26, 2012
    Posts:
    27
    This is the first response on Google now, are you proud of yourself?
     
    Xain and Xelalego like this.
  13. ChristmasEve

    ChristmasEve

    Joined:
    Apr 21, 2015
    Posts:
    45
    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*
     
  14. AndiKubi

    AndiKubi

    Joined:
    Jul 12, 2023
    Posts:
    1
    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.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerAnimation : MonoBehaviour
    6. {
    7.     private Animator anim;
    8.  
    9.     private PlayerAnimation playerAnim;
    10.  
    11.  
    12.     private void Awake()
    13.     {
    14.         anim = GetComponent<Animator>();
    15.         playerAnim = GetComponent<PlayerAnimation>();
    16.     }
    17.  
    18.  
    19.     public void Play_WalkAnimation(int walk)
    20.     {
    21.         anim.SetInteger(TagManager.WALK_ANIMATION_PARAMETER, walk);
    22.     }
    23.  
    24.     public void PLay_JumpAnimation(bool jump)
    25.     {
    26.         anim.SetBool(TagManager.JUMP_ANIMATION_PARAMETER, jump);
    27.     }
    28.  
    29.  
    30.  
    31.  
    32.     // THIS PART HERE   |
    33.     //                                 |
    34.     //                                V
    35.     public void SetFacingDirection(int facingDir)
    36.     {
    37.         if (facingDir > 0)
    38.         {
    39.             // Code to execute when facingDir is greater than 0
    40.             // For example:
    41.             playerAnim.transform.localScale = new Vector3(1f, 1f, 1f); // Set the local scale of the player to (1, 1, 1) to maintain the original orientation
    42.         }
    43.         else if (facingDir < 0)
    44.         {
    45.             // Code to execute when facingDir is less than 0
    46.             // For example:
    47.             playerAnim.transform.localScale = new Vector3(1f, 1f, -1f); // Set the local scale of the player to (-1, 1, 1) to mirror the player horizontally
    48.         }
    49.     }
    50.  
    51. }
     
  15. hdaniel_unity

    hdaniel_unity

    Joined:
    Dec 30, 2021
    Posts:
    14
    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.
     
    TobyWu likes this.