Search Unity

Resolved Ruby 2D Kit - Enemy Keeps Flipping Back and Forth When it Walks to Right

Discussion in 'Getting Started' started by Inventory_Status, Nov 25, 2021.

  1. Inventory_Status

    Inventory_Status

    Joined:
    Dec 31, 2020
    Posts:
    42
    Hello,

    I'm having issues with animating my enemy character during the Ruby 2D Kit Tutorial, specifically here at this link:

    https://learn.unity.com/tutorial/sp...66dbedbc2a0021b1bc7c#5d66643fedbc2a00236ddbf2

    I followed all of the steps between Parts 5-9 where we animate the enemy character. However, when I click play and the character animates, as the enemy walks to the right, the animation keeps flipping back and forth between left and right walking animations. Can anyone explain why this is happening?

    I'm using Unity version 2020.2.1f1, on a MacBook pro.

    According to the screenshot below, I have all of my frames set to the Flip X version so that the enemy can walk to the right:

    Animation Enemy walking right settings.png

    Here is the video of the issue:



    Also, please follow my Youtube Channel: A Walkthrough by Forbidden Kraken. My videos of any issues (including the one above) will be posted there (there is no option to upload my video directly from my computer).

    Thank you all!
     
    Last edited: Nov 25, 2021
  2. Inventory_Status

    Inventory_Status

    Joined:
    Dec 31, 2020
    Posts:
    42
    Hi all,

    I just realized the problem: I accidentaly have an extra walking left animation in my WalkingRight Animation (double check the screenshot above, notice that there are 5 sprites (keys) when there should only be 4!

    In addition, I have the following code below in c# in the wrong place:

    Code (CSharp):
    1. if (vertical)
    2.         {
    3.             position.y = position.y + Time.deltaTime * speed * direction;
    4.             animator.SetFloat("Move X", 0);
    5.             animator.SetFloat("Move Y", direction);
    6.         }
    7.         else
    8.         {
    9.             position.x = position.x + Time.deltaTime * speed * direction;
    10.             animator.SetFloat("Move X", direction);
    11.             animator.SetFloat("Move Y", 0);
    12.         }
    13.        
    it was in void Update when it should have been in void FixedUpdate. I realized this immediately when I changed my direction timer in my enemy's Inspector.

    This is where running our code every certain number of steps is very important!
     
    Last edited: Nov 25, 2021