Need help using rotation of another GameObject

Hello everyone,

I have a small problem when using the rotation of GameObject A and use it for other GO’s. Basically I have this cube and 3 cylinders (fbx model), one cylinder for each axis, in the code I have added the rotation values for each cylinder so they dont get overlaid.

Now when I rotate the cube, the indicators should follow. I tried using the cylinders as childs but thats no option for me as to the scaling issue of child elements which I want to avoid.

When I rotate the object the X and Y-Axis cylinder works fine except the one for the Z-Axis. Once I start rotating the object its all over the place, I also made a short video for demonstration…

    public GameObject CylinderXAxis;
    public GameObject CylinderYAxis;
    public GameObject CylinderZAxis;
 
    void Update()
    {
        var eulerAngles = this.transform.eulerAngles;
     
        Vector3 newScaleX = new Vector3(eulerAngles.x, eulerAngles.y, eulerAngles.z + 90);
        CylinderXAxis.transform.eulerAngles = newScaleX;

        Vector3 newScaleY = new Vector3(eulerAngles.x, eulerAngles.y, eulerAngles.z);
        CylinderYAxis.transform.eulerAngles = newScaleY;

        Vector3 newScaleZ = new Vector3(eulerAngles.z, eulerAngles.y - 90, eulerAngles.z + 90);
        CylinderZAxis.transform.eulerAngles = newScaleZ;
    }

Any help is apreciated.

best regards,
Alex

Make all of the objects children of an empty parent, then rotate the parent instead of the cube. Then you can scale any one of the child objects to your heart’s content without touching the cylinders. Best of all, you don’t need any scripts (other than for rotating the parent).

5803105--613531--upload_2020-5-4_14-3-20.png

5803105--613531--upload_2020-5-4_14-3-20.png

1 Like

easy solution, I was totally overthinking it :slight_smile: thanks, works like a charm