rotation – How do I rotate shoulder bone up and down using Rotate and Space.World independend on model orientation


I wanted to move my character’s arms up and down in a straight way.

The Rotation Gizmo tool can do exactely that.

Playing with the wheel of the Rotation Gizmo tool in the attached screenshot (marked with red arrows in my screenshot), I could move the arms down in a straight way:

enter image description here
enter image description here

I can do the same using the following script:

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

public class MyPlayer : MonoBehaviour
{
    public Transform Shoulder;

    private Quaternion _Rotation;
    private float _f = 0f;

    private void OnGUI()
    {
        if (GUI.Button(new Rect(0, 70, 50, 30), "+"))
        {
            _f += 1;
            Shoulder.Rotate(_f, 0, 0, Space.World); ;
        }
    }
}

This works perfectly fine, but no longer when I rotate the main model (=the parent of the shoulder).

How could I make this script independend on the main transform’s orientation?

Thank you!

Edit:

I would guess that I have to take the main transform (=parent) orientation into account in order to subtract its global rotation from the calculations, but not really knowing which values I should choose, I didn’t find the correct formula. However, FYI, I tried the following:

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

public class MyPlayer : MonoBehaviour
{
    public Transform Shoulder;

    public Transform Mother;

    private float _f = 0f;

    private void OnGUI()
    {
        if (GUI.Button(new Rect(0, 70, 50, 30), "+"))
        {
            _f += 1;
            _f -= Mother.transform.rotation.eulerAngles.x;
            Shoulder.Rotate(_f, 0, 0, Space.World); ;
        }
    }
}