Animation gets stuck halfway through (Unity 5)

Short version: I’m trying to play a simple animation that rotates a soccer player 360° around the z axis. This works about half the time, but the other half, the player gets stuck halfway through, and the animation stops prematurely.

In this simple soccer game, the player is either running, standing around, or doing a bicycle kick. Here’s the animation state machine:

alt text

The transitions seem to work fine, the running animation plays when the player runs, stops when he stops, and when I hit the bicycle kick button, the bicycle kick animation triggers. The problem occurs during the bicycle kick animation.

This is the transition back from bicycle kick to idle:

!

This is the only transition going out of the bicycle kick state.

The animation is supposed to play once, then immediately go back to the idle animation and, if the player is running, continue to isRunning. I’m triggering transitions like this:

	if (!animator.GetCurrentAnimatorStateInfo(0).IsName(animationName)) {
		animator.SetTrigger(animationName);
	}

The idle animation is completely empty.

The bicycle kick animation sets the player’s z-rotation to -360 degrees at the beginning, and then rotates him back to 0 degrees:

alt text

The player that’s being rotated looks like this:

alt text

The reason why there’s a Rotatable GameObject containing a Direction GameObject containing the actual sprites is that I’m using Rotatable to do the bicycle kick animation, and I’m using Direction to turn the player in the direction he’s running.

(I also intend to use these two GameObjects to manipulate the pivot point for the animation, by moving one down and the other one up by the same distance.)

All of this works perfectly about 50% of the time. The remaining 50% of the time, the animation triggers fine, but then gets stuck midway through. Here’s an animated gif showing the effect:

alt text

(At the moment, the player rotates “into the ground”, and I intend to also make him jump at the same time by increasing the y velocity, so it looks like a real bicycle kick, but I’m trying to remove all factors that could have an impact on the animation, so that’s not happening in the gif. At any rate, jumping did not help; the problem occurs regardless of whether the player rotates “into the ground” or not.)

Any hints would be hugely appreciated.

I have now figured out what triggers the problem. Like outlined above, I have two nested GameObjects, one that does the animation (Rotatable), and another one that turns the player into the correct direction based on whether he’s running to the left or to the right (Direction).

alt text

i change the Direction GameObject’s direction programmatically, e.g. like this:

rotation = new Vector3(0f, 180f, 0f);
direction.transform.eulerAngles = rotation;

This is what seems to interrupt the animation.

I don’t understand why it does so, since the animation occurs in a different GameObject, but at least now I have a starting point for trying to figure out how to fix this problem. I guess I should use animations for turning the player, but turning and doing other animations are completely orthogonal things that should happen independently of each other.

Addendum: Using direction.transform.Rotate instead of direction.transform.eulerAngles seems to have fixed the problem.

Vector3 rotation = new Vector3(0f, 180f, 0f);
direction.transform.Rotate (rotation);

I was facing a similar issue but my problem was different.
I had a Animator controller attached to the parent GameObject and another Animator attached to the child where both performed transform animations.

The parent Animator can animate any of their child elements, so it’s not good having different animators among different Hierarchies.