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...
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...