I am trying to animate a warrior I have created a Finite State Machine as shows the following image. There are three transition parameters: btn_walking, btn_jumping and btn_attacking. When the user holds the key w the btn_walking parameter is set to true, the same occurs to btn_jumping and btn_attacking when the keys j and a are hold, respectivelly.
However, it takes some time to transit from one state to another. When the warrior is on player_iddle state and I hold the key w, for example, the animation does not change immediately to the player_walking state. And it is very noticeable. The same occurs to transit beetwen any other states. Does someone know what I should do to the transition be triggered immediately when a key is typed?
I have realized that increasing the FPS to each animation the time answer to transit from one state to other decreased. However, this makes the animations strange because the turned too much fast.
I am providing a link where you can download my project for you analyzing the code and helping me.
To the warrior (GameObject player_sprite) is atteched the following script (player.cs):
public class player : MonoBehaviour {
private Animator animator;
bool btn_walking = false;
bool btn_jumping = false;
bool btn_attacking = false;
// Use this for initialization
void Start () {
animator = this.GetComponent();
}
// Update is called once per frame
void Update() {
btn_walking = false;
btn_jumping = false;
btn_attacking = false;
if(Input.GetKeyDown(KeyCode.W)){
animator.SetBool(“btn_walking”, true);
}
if(Input.GetKeyUp(KeyCode.W)){
animator.SetBool(“btn_walking”, false);
}
if(Input.GetKeyDown(KeyCode.J)){
btn_jumping = true;
Debug.Log (“clicked on J”);
animator.SetBool(“btn_jumping”, true);
}
if(Input.GetKeyUp(KeyCode.J)){
animator.SetBool(“btn_jumping”, false);
}
if(Input.GetKeyDown(KeyCode.A)){
btn_attacking = true;
animator.SetBool(“btn_attacking”, true);
}
if(Input.GetKeyUp(KeyCode.A)){
animator.SetBool(“btn_attacking”, false);
}
}
}
the project: https://drive.google.com/open?id=1gFs01ZAzs0JlPKi39gYxUJiGLJLx_1GE
Thank you.
