Spine rotation is not working while animation

Hey guys,
I want to rotate the spine of my player when I look upwards or downwards. This works if turn of the animator, but not if it’s on. I tried a lot of variations but it didn’t work.
So, here is my code and I could need some help.

Thanks,
Barney

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    private CharacterController characterController;
    private Transform spine;

    private Animator animator;

    [SerializeField]
    private float sensitivity = 100f;
    [SerializeField]
    private float forwardMovemSpeed=2f;
    [SerializeField]
    private float backwardMoveSpeed = 1.5f;
    [SerializeField]
    private float sidewaysMoveSpeed = 1.5f;

    float rot;
    private void Awake()
    {
        characterController = GetComponent<CharacterController>();
        animator = GetComponentInChildren<Animator>();
        spine = animator.GetBoneTransform(HumanBodyBones.Spine);

        Cursor.lockState = CursorLockMode.Locked;
    }
    void Update()
    {
        var vertical = Input.GetAxis("Vertical");
        var horizontal = Input.GetAxis("Horizontal");
        var mouseX = Input.GetAxis("Mouse X");

        animator.SetFloat("InputX", vertical);
        animator.SetFloat("InputY", horizontal);

        transform.Rotate(Vector3.up, mouseX * Time.deltaTime*sensitivity);

        if (vertical != 0)
        {
            float moveSpeedToUse = (vertical > 0 )? forwardMovemSpeed : backwardMoveSpeed;
            characterController.SimpleMove(transform.forward * moveSpeedToUse * vertical);
        }
        if (horizontal != 0)
        {
            characterController.SimpleMove(transform.right * horizontal);

        }
    }
    private void LateUpdate()
    {
        var mouseY = -Input.GetAxis("Mouse Y");
        rot = mouseY * Time.deltaTime * sensitivity;
        Debug.Log(rot);
        spine.transform.Rotate(Vector3.right,rot);

    }
}

Your issue is that rot is not an accumulative value, but rather a single delta change since last frame.

Store your desired rotation as a variable. (Add it each frame)
Then override the spine.transform.rotation on each late update to avoid animator interrupting your rotation.

1 Like

Thank you, it worked