Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Bug Spine rotation causes strange offset

Discussion in 'Animation' started by samson96, Apr 30, 2023.

  1. samson96


    Jan 8, 2020
    Hello everyone. I've run into a strange problem recently. I have a humanoid character with a simple animator with reloading animation. The character also has a script, that rotates the spine in root bone space in LateUpdate. Also, I have a debug sphere parented to the head bone, and before applying spine rotation I set the sphere to transform to some point in character space (p.s. by root and character space I mean the same thing - the root space of the character).

    So the expected behavior is this: debug sphere is not affected by the animation, and it's rotated by procedural spine modification.

    This works only if the spine rotation angle is 0, otherwise, the sphere sways a lot. I also tested it by rotating the spine bone in local space, but they had the same issue.

    Does anyone have an idea why it happens? I suspect it's the way Unity updates transform, but I'm not sure. Also, how can I achieve the desired behavior described above? I really appreciate any help.

    Video of the problem:

    Code (CSharp):
    1. public class SpineRotation : MonoBehaviour
    2. {
    3.     [Range(-90, 90)] public float angle = 0;
    4.     public Transform sphere;
    5.     public Transform spine;
    6.     public Vector3 offsetMS;
    8.     private Quaternion Rotate(Transform space, Transform bone, Quaternion rotation)
    9.     {
    10.         return space.rotation * (rotation * Quaternion.Inverse(space.rotation) * bone.rotation);
    11.     }
    13.     private void LateUpdate()
    14.     {
    15.         sphere.position = transform.TransformPoint(offsetMS);
    16.         sphere.rotation = transform.rotation;
    17.         spine.rotation = Rotate(transform, spine, Quaternion.Euler(angle, 0f, 0f));
    18.     }
    19. }