Head Rotation while Animation is played

Hello there,

I’m working on a small 3d multiplayer game where the head rotates with the camera. so if you look down your character looks downward too and the others can see it.

However when i do that all animations stop.

In the Project is just a Scene with a flat terrain and the Character so far.

The character looks like the one in Minecraft and has an armature with Torso,Head,Leg,Arm bones. All bones are conncted to the Torso.

The Animations were made with the Unity buildin Animator and are played with bools inside the Animator, which are controled by a simple if(input) walkanimation = true; script.

The Character is using the standard First Person Controller along with the MouseLook script that unity has as a standard asset.

I’ve tried several approaches, but none really work.

**

1st approach:

**

  • Made the Camera the Head-bones child. So it moves with the Head.
  • Change the Object, that is moved by the MouseLook script to the Head instead of the Camera.

outcome :
Head moves properly, character walks, but animation stops as soon as the player moves the mouse.

**

2nd approach:

**

  • Made the Camera the child of the characters-main-object . it Doesn’t move the Head but inherits the Y rotation and the position.
  • MouseLook Script Moves the Camera.
  • attached a new script with the following code to the head

transform.eulerAngles = new Vector3 (Camera.main.transform.eulerAngles.x,Camera.main.transform.eulerAngles.y,Camera.main.transform.eulerAngles.z);


outcome :
Head moves properly, character walks, but animation stops as soon as the player moves the mouse.

**

3rd approach:

**

  • don’t use the Uniy Animation system and instead Program a script that does the whole animation with .Lerp functions. VERY TIME CONSUMING…

  • Made the Camera the child of the characters-main-object . it Doesn’t move the Head but inherits the Y rotation and the position.

  • MouseLook Script Moves the Camera.

  • attached a new script with the following code to the head

    transform.eulerAngles = new Vector3 (Camera.main.transform.eulerAngles.x,Camera.main.transform.eulerAngles.y,Camera.main.transform.eulerAngles.z);


outcome :
Head moves properly, character walks, “animation” is played properly. so it acutually works, but consumes way to much time to do several animations like this.

**

Conclusion:

**

If while playing an animation a script changes the rotation of a bone, all animations stop. Because the Script seems to have higher priority than the Animation does.

possible fix:

  1. change the priority order.
  2. find a script command that doesn’t stop the animations
  3. find another way that doesn’t interfere with the animtions


But i have no idea how to do any of this.

You canshould be able to do it like this:

Instantiate an empty gameobject at the neck bone’s position. Make the head bone a child of this empty GO. The bone hierarchy is now broken at the head, But that doesn’t matter. Use AddMixingTransform1 to give any (preferably empty, meaning no head movement taking place) animation clip the head bone transform. Play the animation just to be sure. The normal move etc. animations should work as usual until they reach the neck.

It will probably require A LOT of trial and error, I know because I spend more than a week IIRC getting this to work. For my project, I wanted a character to get into a shooting pose, and then turn the torso towards the target and play the shooting animation for the torso only. It’s a mess with parenting/unparenting, Add/Remove MixingTransforms, Animation.Play and CrossFade… But in the end it works. Maybe you can even use layers?

Just adding the gameObject to break the bone hierarchy works great for me. Thank you.