Using Unity 2019.4.1f1 Personal.
I have the above Animation Controller. When only walking in one direction at a time and when you stop you stay facing that direction, this works as planned.
All of the transitions do not have an exit time and have a fixed duration of 0. I don't know what info to give as this is the first time I've used animation. Let me know and I'll add relevant details.
Here's my update function that updates the variables in the animator:
void Update() {
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
animator.SetFloat("Horizontal", h);
animator.SetFloat("Vertical", v);
if (Mathf.Abs(v) < Mathf.Abs(h)) {
// flips the renderer to reuse other handed image
spriteRenderer.flipX = h > 0;
}
// no actual movement until I figure this out
}
What I'm experiencing that I want to fix is when running diagonally:
It seems that when walking diagonally then the animator variables for Horizontal
and Vertical
are both either 1 or -1 and this causes the alternating of the sprites. What I'd like to happen is that the state machine would deterministically pick either N/S sprites or E/W sprites when moving diagonally. Turning on "Can Transition To Self" seems to properly pick a direction and stick to it but it fails to animate when only moving in a single direction. It looks like it's constantly transitioning to itself which starts over the cycle so I've left that unchecked on all transitions.
I'm not sure what the best way to fix this is. Most attempts I've tried so far complicate the state machine to the point it's unmaintainable. I also couldn't find anything about introducing priorities in a way that fixed the jitter.
What's the idiomatic Unity way to achieve clean diagonal movement in 2D?
or
logic and wouldn't help. If I can't define "condition AND condition" how would I even write a diagonal transition? \$\endgroup\$or
logic" Rather than assume, did you stop to experiment, or check the docs? "If your transition has one or more conditions, the conditions must all be met before the transition is triggered." Have you tried adding an extra condition to your horizontal state transitions to keep them from triggering when your vertical states are active? \$\endgroup\$