I’ve got a pretty basic setup:
Player can only move left or right.
I have looping animations for Idle, Left and Right.
I also have animations that play between all of them:
“Idle to Left,” “Left to Idle,” “Idle to Right,” “Right to Idle,” “Left to Right” and “Right to Left”
I did originally set this all up using triggers, the state machine looks like an insane web, and for the most part it works, but it’s buggy. The player will get stuck in certain animations sometimes, or won’t continue through the transition animation, etc.
I’m sure my code is the culprit, but I’m looking for a way to redo the whole thing properly.
Are there any tutorials out there for this? All I can find are controlling basic sprites: Idle to Run, Idle to Jump, etc… nothing with transition animations.
I’m not sure if I should set this up using triggers, having a “Speed” float, bools, etc, or a combination of them.
I just feel like I am making this way more complicated than it has to be.
Here is the main part of my code that controls the animation:
if (moveHorizontal < 0) {
if (GlobalControl.direction == "right") {
resetAllTriggers ();
animator.SetTrigger ("playerRightToLeft");
} else {
resetAllTriggers ();
animator.SetTrigger ("playerStraightToLeft");
GlobalControl.direction = "left";
}
}
if (moveHorizontal > 0) {
if (GlobalControl.direction == "left") {
resetAllTriggers ();
animator.SetTrigger ("playerLeftToRight");
} else {
resetAllTriggers ();
animator.SetTrigger ("playerStraightToRight");
GlobalControl.direction = "right";
}
}
if (moveHorizontal == 0
&& (animator.GetCurrentAnimatorStateInfo (0).IsName ("Player-LeftToRight") == false)
&& (animator.GetCurrentAnimatorStateInfo (0).IsName ("Player-RightToLeft") == false)) {
if (GlobalControl.direction == "left") {
resetAllTriggers ();
animator.SetTrigger ("playerLeftToStraight");
} else if (GlobalControl.direction == "right") {
resetAllTriggers ();
animator.SetTrigger ("playerRightToStraight");
}
}
The GlobalControl.direction is also being set in the “Left to Right,” “Right to Left,” and “Right/Left to Straight” onStateExit() callback.
It all just seems so convoluted and I feel there must be a better way!
Any suggestions on how to go about this would be great!
Thanks so much.