Flip Animations

I’ve created 2 layers (face right and face left). When character facing left, it can move forward to left but with the animation of facing right’s backward. When moving backward, it will use facing right’s forward, appreciate somebody can advise, thanks.

void Update()
{
// listen to the animator
Player1Layer0 = Anim.GetCurrentAnimatorStateInfo(0);

    // Screen border set up (X axis)
    Vector3 ScreenBounds = Camera.main.WorldToScreenPoint(this.transform.position);

    if(ScreenBounds.x > Screen.width - 70)
    {
        CanWalkRight = false;
    }
    if (ScreenBounds.x < 50)
    {
        CanWalkLeft = false;
    }
    else if (ScreenBounds.x > 50 && ScreenBounds.x < Screen.width - 70)
    {
        CanWalkRight = true;
        CanWalkLeft = true;
    }

    //get the opponent's position
    OppPosition = Opponent.transform.position;

    //facing left or right of the Opponent
    if(OppPosition.x > Player1.transform.position.x)
    {
        StartCoroutine(FaceLeft());
    }
    if (OppPosition.x < Player1.transform.position.x)
    {
        StartCoroutine(FaceRight());
    }

    // Walking left and right
    if (Player1Layer0.IsTag("Motion"))
    {
        if (Input.GetAxis("Horizontal") > 0)
        {
            if (CanWalkRight == true)
            {
                Anim.SetBool("forward", true);
                transform.Translate(WalkSpeed, 0, 0);
            }
        }
        if (Input.GetAxis("Horizontal") < 0)
        {
            if (CanWalkLeft == true)
            {
                Anim.SetBool("backward", true);
                transform.Translate(-WalkSpeed, 0, 0);
            }
        }
    }
    if (Input.GetAxis("Horizontal") == 0)
    {
        Anim.SetBool("forward", false);
        Anim.SetBool("backward", false);
    }

I don’t know what’s going on here, but I do see that you are setting “backward” to true when the player can move left. Seems wrong. Maybe it’s not

1 Like

Hi thanks, i just resolved the matter with your idea!

But another issue arised, will open another topic, hopes you can advise as well.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.