Unexpected Y-axis value change during transform

The graph shown on the left should transform into the graph shown on the right. Instead, it transforms to the graph in the middle, which is lower on the y-axis. The graph is constructed from four gameobjects, each one a simple scaled cube with its pivot on its lowest face.


The gameobjects have scaled properly and have moved relative to each other as expected… but they’re lower on the y-axis than expected.

I’m using DOTween’s DOMove and DOScale to get a visually stacked graph to transform its internal segments. Using a regular transform will also cause similar behavior, so I don’t think it’s a DOTween specific problem. Commenting out DOScale did not change the unwanted transform behavior.

What am I missing which could cause this y-axis movement?

Thank you in advance for any help or insight!

    public override void StartShowData ()
    {
        minimalDist = trad_24_minimal_y - trad_24_minimal.transform.position.y;
        moderateDist = trad_24_moderate_y - trad_24_moderate.transform.position.y;
        severeDist = trad_24_severe_y - trad_24_severe.transform.position.y;
        cripplingDist = trad_24_crippled_y - trad_24_crippled.transform.position.y;

        Debug.Log ("start y: " + trad_24_minimal.transform.position.y + ", to y: " + trad_24_minimal_y + ", totalling " + minimalDist);
        trad_24_minimal.transform.DOMove (new Vector3 (trad_24_minimal.transform.position.x, trad_24_minimal_y, trad_24_minimal.transform.position.z), _transDuration, false);
        trad_24_minimal.transform.DOScaleY (trad_24_minimal_scale, _transDuration);
   
        Debug.Log ("start y: " + trad_24_moderate.transform.position.y + ", to y: " + trad_24_moderate_y + ", totalling " + moderateDist);
        trad_24_moderate.transform.DOMove (new Vector3 (trad_24_moderate.transform.position.x, trad_24_moderate_y, trad_24_moderate.transform.position.z), _transDuration, false);
        trad_24_moderate.transform.DOScaleY (trad_24_moderate_scale, _transDuration);

        Debug.Log ("start y: " + trad_24_severe.transform.position.y + ", to y: " + trad_24_severe_y + ", totalling " + severeDist);
        trad_24_severe.transform.DOMove (new Vector3 (trad_24_severe.transform.position.x, trad_24_severe_y, trad_24_severe.transform.position.z), _transDuration, false);
        trad_24_severe.transform.DOScaleY (trad_24_severe_scale, _transDuration);

        Debug.Log ("start y: " + trad_24_crippled.transform.position.y + ", to y: " + trad_24_crippled_y + ", totalling " + cripplingDist);
        trad_24_crippled.transform.DOMove (new Vector3 (trad_24_crippled.transform.position.x, trad_24_crippled_y, trad_24_crippled.transform.position.z), _transDuration, false);
        trad_24_crippled.transform.DOScaleY (trad_24_crippled_scale, _transDuration);

    }

I’m assuming minimal is the bottom one? What’s happening is that trad_24_minimal_y is less than 0 (-1.41 according to your log) while what you want to do is hardcode it to be 0, and then do your calculations from that.

Thank you; I’ll take a look at that.

Actually, it seems related to my gameobjects being parented to an Empty Game Object with non-zero Transform coordinates.

I’m trying to move in a Vector3 with the shown coordinates in the Inspector, but DOMove keeps moving to world coordinates, while the Inspector is showing things relative to the parent.

Maybe try to get it working without DOTween first, to rule that out as a problem. What you’re seeing in the inspector is the transform.localPosition, which is probably what you should be using in your method if you want to move it around with the parent. I’ve never used DOTween, but from the documentation they seem to have a DOLocalMove which is probably what you’re after in that case.

1 Like