Rotate bones in Unity and play canned animation relative to rotation

Hey guys,

I’m trying to make a character that is fully animated, but I am able to rotate some of the bones in Unity and still play the animations. Currently, I have a basic setup with a torso that links to a pair of shoulders that link to 2 hands and a head by itself. When this is imported into Unity, it gives you the hierarchy like so:

main mesh
____________head
____________torso–>
__________________shoulders

I want to be able to rotate these three components and still play their animations relative to the new rotation. E.g, the head is turned left, the torso is right, the shoulders are rotated up, and if I play a swinging animation (with the hands bound to the shoulders and shoulders to the torso) they’ll swing to the right and up.

If I try to do this now with this setup, it resets to the original rotation. I can’t just make a bunch of dummy gameobjects and make these their children (which would technically work) because that would break the hierarchy and kill the animations.

I’m currently using the Legacy animation system with the Generation set to Store in Root (new). Is there a setting that will make the animations play relative to rotations?

This seems like it should be a pretty common problem in games (get a character to look at something while playing animations) but I haven’t figured out a simple solution in Unity. If mechanim has a solution I’d be open to it, but I have zero experience with it and since this is for a prototype I’d prefer to stick with Legacy if possible.

Thanks,

Erik

[RESOLVED]

Hey, figured this one out. Apparently all of the animations are imported to play in world space, and there’s no way around this. What you can do however, is manipulate the object in LateUpdate and the transforms will stick. I’m assigning this script:

using UnityEngine;
using System.Collections;

public class AdditiveTransform : MonoBehaviour {

    [HideInInspector]
    public Quaternion localRotation;

    private Quaternion startingLocalRotation;

	// Use this for initialization
	void Start () {
        startingLocalRotation = transform.localRotation;
	}

    void LateUpdate()
    {
        transform.localRotation = startingLocalRotation * localRotation;
    }
}

To all my objects I want to be able to rotate locally during animation, and it works. Updated the title to make it easier to search in the future.

Resolved, added fix in OP.