1
\$\begingroup\$

I have my player's animation controller managing two simple states: idle-walk. States are switched via bools and everything works fine aside from the fact that the idle state doesn't render the first run of the animation loop.

To make it more clear when I start the game, in the animator I see the idle animation properly starting immediately (the azure bar loads immediately) but the player gets actually animated only after the first run of the animation, and the same goes when exiting the walk animation back to idle.

This is the animation structure, that very first idle cycle run in the controller but the player actually stands still...

enter image description here

Here's the function that move the player and set relative bools for animation switching:

public void MovePlayer(float horizontalInput)
{

    bool onEdge = playerTransform.position.x <= -2.5f || playerTransform.position.x >= 2.5f;
    float animSpeed = Mathf.Clamp(Mathf.Abs(horizontalInput) * 1f, 0.5f, 1f);
    anim.SetFloat("movingSpeed", animSpeed);

    if(horizontalInput < -0.2f && !onEdge)
        anim.SetBool("movingL", true);
    else if (horizontalInput > 0.2f && !onEdge)
        anim.SetBool("movingR", true);
    else
    {
        anim.SetBool("movingL", false);
        anim.SetBool("movingR", false);
    }

    nextPosX = Mathf.Clamp(playerTransform.position.x + (horizontalInput * playerSpeed * Time.deltaTime), -2.5f, 2.5f);

    playerTransform.position = new Vector2(nextPosX, 0);                                                    
}

The movingL/R bools are set true when the horizontal input pass a certain threshold and are set to false (back to idle) under that threshold. Hope this is clear enough...

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Show some code and/or screenshots. \$\endgroup\$ Commented Jul 28, 2016 at 15:09
  • \$\begingroup\$ The code just triggers the bools to enter the moving states. I don't think it's code related since the problem is present even at first runtime when the idle state is entered automatically... \$\endgroup\$
    – Uknowho
    Commented Jul 28, 2016 at 16:06
  • \$\begingroup\$ A good question should present all related materials in a brief way. You can't really know if your code has a tiny bug that you overlooked. \$\endgroup\$ Commented Jul 28, 2016 at 16:08
  • \$\begingroup\$ Added the code. Still I think it's somehow related to the animation controller processes because of what I said before... \$\endgroup\$
    – Uknowho
    Commented Jul 28, 2016 at 16:21

0

You must log in to answer this question.

Browse other questions tagged .