Rotation Problem (689609)

Hello all,

I am developing a glove with flexible sensors which controls the finger movements of the hand model in Unity. I am sending the sensor data via UDP and parsing it in Unity.

When I change the angle on the Y axis (with localEulerAngles as you see below), I expect the thumb finger geometry to change only on the Y axis. But as you see, there is a change in all axes.

What is wrong with this? Can you help me?

Unity Editor

The Code with explanation

Code in text format

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

public class controller : MonoBehaviour {

    public static controller instance;
    public float[] newNormalizedValues;

    float thumb1Angle;
    public GameObject thumb1;
    private float thumb1Open = 150;
    private float thumb1Close = 100;

    void Start () {
        instance = this;
        Screen.SetResolution(500, 500, false);
    }
       
    void Update () {
        thumb1Angle = thumb1.transform.localEulerAngles.y;
        Debug.Log (thumb1Angle);
        float newAngle = (thumb1Open - (thumb1Close - thumb1Open) * udpParser.mcpBas);
        Debug.Log (udpParser.mcpBas);
        thumb1.transform.localEulerAngles = new Vector3(thumb1.transform.localEulerAngles.x, newAngle, thumb1.transform.localEulerAngles.z);
    }
}

It looks fine to me, you’re rotating on the Y axis but the X and Z are also set. If you want to only rotate on the Y axis you need to set the X and Z to 0.

It sounds like what you want to do is add a world Y rotation onto a local XYZ rotation.

To do that you would need to do this:

In Start function keep a copy of the initial localEulerAngles

In Update set thumb1.transform.localEulerAngles to the copy (so it’s set to the original angle)

Apply a world Y rotation afterwards using Transform.Rotate( new Vector3( 0.0f , newAngle , 0.0f ) , Space.World)