0

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); ;
    }
}

}

tmighty
  • 919
  • 13
  • 38
  • Do you want the gizmo to operate like it's in "local" mode, or "global" mode? (You've cropped this part out of your screenshot) – DMGregory Sep 06 '20 at 23:41
  • @DMGregory I have added a top menu screenshot to my post. I think it's the Global mode, but not 100% sure about it. – tmighty Sep 07 '20 at 06:45

0 Answers0